feat: validate token format in both PHP and CLI

This commit is contained in:
Eli Bosley
2025-01-27 09:49:17 -05:00
parent 3734730bf7
commit b9d9105e3e
2 changed files with 9 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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 {