00:00

#0208

OAuth Scope Widening

Medium+100 XPA01:2021 Broken Access ControlCWE-269
OAuthScopePrivilege Escalation

Scenario

An OAuth 2.0 authorization server issues tokens with a set of scopes the user explicitly approved (e.g. read:profile, read:orders).

When the client later requests a new access token via token refresh or a downstream scope-check, it passes a list of requested scopes. The server must verify that every requested scope was already granted by the user.

The buggy implementation simply returns whatever the client asks for, silently granting scopes like write:orders or admin that the user never approved — a classic OAuth scope widening attack.

OAuth scope widening lets a malicious or compromised client silently escalate its own privileges. A single missing intersection check can turn a read-only token into an admin token without the user's knowledge.

Your Tasks

  1. Fix filterScopes so it returns only the scopes present in both requestedScopes and grantedScopes.
  2. If none of the requested scopes were granted, return an empty array.
  3. Legitimate scopes the user granted must still be returned when requested.

Examples

Example 1Scope widening blocked

filterScopes(['read:profile','write:orders','admin'], ['read:profile','read:orders'])
// write:orders and admin were never granted
// → ['read:profile']

Example 2All requested scopes granted

filterScopes(['read:profile','read:orders'], ['read:profile','read:orders'])
// → ['read:profile','read:orders']

Constraints

  • Only edit the function body — do not change the function signature.
  • Return a string[] containing only the intersection of the two input arrays.
  • Order of the returned scopes should match the order they appear in requestedScopes.
  • No external packages.

Hint

References

solution.js
Ln 1, Col 1UTF-8JavaScript
Sandbox ready
0/0/0not run