-
Notifications
You must be signed in to change notification settings - Fork 2
fix(oauth2): use exact matching for JS client origin validation #545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,9 +171,13 @@ public function handle($request, Closure $next) | |
| ); | ||
| throw new InvalidGrantTypeException(OAuth2Protocol::OAuth2Protocol_Error_InvalidToken); | ||
| } | ||
| $allowedOrigins = array_filter(array_map( | ||
| fn($o) => rtrim(trim($o), '/'), | ||
| explode(' ', $token_info->getAllowedOrigins() ?? '') | ||
| )); | ||
| if ( | ||
| $token_info->getApplicationType() === 'JS_CLIENT' | ||
| && (is_null($origin) || empty($origin)|| str_contains($token_info->getAllowedOrigins(), $origin) === false ) | ||
| && (is_null($origin) || empty($origin) || !in_array(rtrim($origin, '/'), $allowedOrigins, true)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mulldug
Combined with strict Failure mode is silent and uniform across affected clients, and local tests won't catch it (fixtures use Suggested fix: normalize each entry through the same $allowedOrigins = array_filter(array_map(function ($o) {
$o = trim($o);
if ($o === '') return '';
try { $o = (new \URL\Normalizer($o))->normalize(); } catch (\Throwable $e) {}
return rtrim($o, '/');
}, explode(' ', $token_info->getAllowedOrigins() ?? '')));Recommended pre-rollout check: query the token store for |
||
| ) { | ||
| //check origins | ||
| throw new OAuth2ResourceServerException( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mulldug
Move the array build inside the JS_CLIENT branch so server-to-server tokens do not pay the cost