mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: validate token format in both PHP and CLI
This commit is contained in:
@@ -23,8 +23,11 @@ function verifyUsernamePasswordAndSSO(string $username, string $password): bool
|
||||
// We may have an SSO token, attempt validation
|
||||
if (strlen($password) > 800) {
|
||||
$safePassword = escapeshellarg($password);
|
||||
if (!preg_match('/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/', $password)) {
|
||||
my_logger("SSO Login Attempt Failed: Invalid token format");
|
||||
}
|
||||
$response = exec("/usr/local/bin/unraid-api sso validate-token $safePassword", $output, $code);
|
||||
my_logger("SSO Login Response: $response");
|
||||
my_logger("SSO Login Attempt: $response");
|
||||
if ($code === 0 && $response && strpos($response, '"valid":true') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,15 @@ export class ValidateTokenCommand extends CommandRunner {
|
||||
}
|
||||
|
||||
const token = passedParams[0];
|
||||
|
||||
if (typeof token !== 'string' || token.trim() === '') {
|
||||
this.createErrorAndExit('Invalid token provided');
|
||||
}
|
||||
|
||||
if (!/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/.test(token)) {
|
||||
this.createErrorAndExit('Token format is invalid');
|
||||
}
|
||||
|
||||
let caughtError: null | unknown = null;
|
||||
let tokenPayload: null | JWTPayload = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user