File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,18 @@ public static function getGithubKeys($username)
4949
5050 public static function testValidSSHKey ($ key_str )
5151 {
52+ $ key_str = trim ($ key_str );
53+ if ($ key_str == "" ){
54+ return false ;
55+ }
56+ // PHP warning when key_str is digits: Attempt to read property "keys" on int
57+ if (preg_match ("/^[0-9]+$/ " , $ key_str )) {
58+ return false ;
59+ }
60+ // PHP warning when key_str is JSON: Undefined property: stdClass::$keys
61+ if (!is_null (@json_decode ($ key_str ))){
62+ return false ;
63+ }
5264 try {
5365 PublicKeyLoader::load ($ key_str );
5466 return true ;
Original file line number Diff line number Diff line change 22
33require "../../../resources/autoload.php " ;
44
5+ use UnityWebPortal \lib \UnitySite ;
56use phpseclib3 \Crypt \PublicKeyLoader ;
67
7- try {
8- PublicKeyLoader::load ($ _POST ['key ' ], $ password = false );
9- echo "true " ;
10- } catch (Exception $ e ) {
11- echo "false " ;
12- }
8+ echo (UnitySite::testValidSSHKey ($ _POST ["key " ]) ? "true " : "false " );
You can’t perform that action at this time.
0 commit comments