forge
Explore
Log in

Don't you dare go Hollow

🔒 oidc: refresh refuses a scope outside its grant instead of ignoring it

Browse files at this commit

1d698444192fba532ac182fbc2f10c961f5a9474Ahmet Kaan GümüşParent: 699ed4c
crates/im-web/src/oidc/token.rsmodified+13 -0
@@ -315,6 +315,19 @@ async fn grant_refresh(app: &AppState, client: &Client, pairs: &Pairs) -> Result
315 if row.client_id != client.id {315 if row.client_id != client.id {
316 return Ok(invalid_grant());316 return Ok(invalid_grant());
317 }317 }
318+ // A refresh keeps the scope of its grant. A scope parameter is refused unless it stays inside that grant,
319+ // so a client never believes it widened or changed its token. The token is not spent on a refusal.
320+ if pairs.iter().any(|(name, _)| name == "scope") {
321+ let within = one(pairs, "scope").is_some_and(|requested| {
322+ requested
323+ .split(' ')
324+ .filter(|s| !s.is_empty())
325+ .all(|s| row.scope.split(' ').any(|g| g == s))
326+ });
327+ if !within {
328+ return Ok(oauth_error(StatusCode::BAD_REQUEST, "invalid_scope"));
329+ }
330+ }
318 if let Some(response) = throttled(331 if let Some(response) = throttled(
319 app,332 app,
320 &token_family_key(&client.id, &row.family_id),333 &token_family_key(&client.id, &row.family_id),