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)
49
49
50
50
public static function testValidSSHKey ($ key_str )
51
51
{
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
+ }
52
64
try {
53
65
PublicKeyLoader::load ($ key_str );
54
66
return true ;
Original file line number Diff line number Diff line change 2
2
3
3
require "../../../resources/autoload.php " ;
4
4
5
+ use UnityWebPortal \lib \UnitySite ;
5
6
use phpseclib3 \Crypt \PublicKeyLoader ;
6
7
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