You copy authorities out of an identity token and into the request's permission set. If any of those values are attacker-reachable, so is admin.
What goes wrong
After login, you build the caller's permissions by reading a list of authority strings, prefixing each one, and dropping them into the request's permission set. Whatever is in that list becomes a role or a scope your access checks will honor a moment later.
The question nobody asked: where does the list come from? If it is populated from identity-provider claims or profile attributes, some of those values can be influenced by the user or by a provider you do not fully control. Nothing validates them against a known set of roles. An attacker who can shape a claim can name the exact administrative role your system checks for, and it lands in the permission set with no objection.
There is no injection trick here and no memory bug. You asked the token what it was allowed to do, and you believed the answer.
The pattern
authorities = []
for name in claims.get('authorities'): # from the token
authorities.append(Role('ROLE_' + name))
context.setAuthorities(authorities) # now trusted
# later:
if context.hasRole('ROLE_ADMIN'):
allow()ALLOWED = {'reader', 'editor', 'auditor'}
roles = rolesForSubject(subject) # your store, not the token
authorities = []
for name in roles:
if name not in ALLOWED:
continue # never invent a role
authorities.append(Role('ROLE_' + name))
context.setAuthorities(authorities)Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.
Why it matters to you
Federated login makes this easy to get wrong. The token feels trustworthy because it is signed, but a signature proves who issued the claim, not that the claim should grant power in your system. Role mapping is your decision, and it belongs on your side of the boundary.
If an attacker can register attributes, influence a directory sync, or use a weakly governed provider, unvalidated authority mapping is a direct path to privilege escalation. Map external identity to internal roles through an allowlist you own, and never let the caller name the role.
Check your own code
- Trace every role or scope back to who can set its source value
- Reject authority names not in an allowlist you maintain
- Derive privileges from your own store keyed by subject, not claims
- Alert when an admin role is assigned from an external attribute