You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
auth: a granted_scopes written before 3.10.1 is treated as the original grant, so a narrowed refresh scope can never be re-requested #1460
When a server narrows the grant on refresh (RFC 6749 §6 allows it), that saved value is the narrowed set, not the original grant. #1433 now preserves any non-empty stored value as the original grant:
let stored_grant = if original_grant.is_empty() && !asked_for_subset {
granted_scopes
}else{
original_grant
};
For records written by 3.10.0 or earlier the upgrade therefore cannot tell "original grant" from "latest access-token scope". With a record that says ["read"] while the refresh token still grants read write:
set_refresh_scopes(["write"]) → refresh_request_scopes (crates/rmcp/src/transport/auth.rs, the kept.is_empty() branch) returns TokenRefreshFailed("none of the refresh scopes ... are in the original grant ...")before any request is sent. Locally unrecoverable.
An unscoped refresh cannot repair it either: asked_for_subset is false but original_grant is non-empty, so the stored grant stays ["read"]. Every later refresh repeats (1).
Net effect: a client that once held read write and was narrowed to read can never ask for write again with that refresh token; only re-authorization gets it back.
Reproduction sketch (no network)
// custom persistent CredentialStore seeded with a pre-3.10.1 recordlet stored = StoredCredentials{client_id:"my-client".into(),token_response:Some(make_token_response_with_refresh("old-token","my-refresh-token")),granted_scopes:vec!["read".into()],// written by 3.10.0 after a narrowed refreshtoken_received_at:Some(AuthorizationManager::now_epoch_secs()),issuer:None,};
store.save(stored).await?;
manager.set_refresh_scopes(["write"]);let err = manager.refresh_token().await.unwrap_err();// TokenRefreshFailed, no HTTP request made
granted_scopes is a single persisted field: to keep both "original grant" and "last access-token scope" the record needs a separately versioned field (or pre-3.10.1 records must be treated as an unknown grant). That is a store-format change with its own migration/compat story, so it belongs in its own PR.
Confirmed at 165f8fd (rmcp 3.11.0) by running it, not by reading the description. Both halves reproduce, and the first one fails before any request leaves the process.
Reproduction
Two tests in transport::auth::tests, in the style of the existing start_token_server tests (local axum /token that captures the request body). Against 165f8fd:
test transport::auth::tests::probe_legacy_narrowed_record_cannot_request_a_wider_scope ... ok
test transport::auth::tests::probe_unscoped_refresh_keeps_the_narrowed_stored_grant ... ok
test result: ok. 2 passed; 0 failed; 900 filtered out
The tests pass because they assert the broken behaviour:
Seeded record granted_scopes: ["read"] (what 3.10.0 wrote after a narrowed refresh), set_refresh_scopes(["write"]), then refresh_token(). Asserted: error is AuthError::TokenRefreshFailed, and the /token handler never received a body (captured is still None). So the request is never sent — nothing at the server can widen it, and on_refresh_token_rejected is not reached; the refresh token is still valid and simply unusable.
Seeded record granted_scopes: ["read"], no refresh scopes set, and a token response that reports "scope":"read write". Asserted: after refresh_token(), the stored record still says ["read"]. The response is discarded for storage purposes, so the next refresh repeats case 1.
Where the code does it
refresh_request_scopes (crates/rmcp/src/transport/auth.rs:2159): kept.is_empty() returns TokenRefreshFailed at :2178-2181 whenever the record's granted_scopes is non-empty and shares nothing with the caller's scopes.
refresh_token (:2603) calls it at :2643-2644, before refresh_request is dispatched, which is what the captured.is_none() assertion pins.
stored_grant (:2706-2710): original_grant is just granted_scopes.clone(), so a legacy narrowed value is preserved as if it were the original grant on both branches.
StoredCredentials.granted_scopes (:277) is the only scope field; it is #[serde(default)], and the struct is #[non_exhaustive].
Why there is no safe one-field fix for (2)
A tempting change is "when !asked_for_subset, store the scopes the response reported". That fixes (2) for this record but regresses records where the stored value is the original grant: an unscoped refresh may still come back narrower under server policy, and the response then says less than the grant. Both populations look identical in the record, so the choice has to come from the record, not from the last response.
Options
A. Add original_grant: Option<Vec<String>> to StoredCredentials (my preference). #[serde(default)], written wherever the grant is actually known — the authorization-code exchange (:2495-2507, and the equivalent in exchange_code_for_token around :3734), carried unchanged through refreshes. On read: Some is authoritative; None means unknown, which should behave like the existing unknown case in refresh_request_scopes (:2170-2172, granted.is_empty()) and let the record be rewritten with what the response reports.
Cost is lower than it looks: the struct is #[non_exhaustive] and every field already has #[serde(default)], so old records deserialize as None and new records still load in an older rmcp — no migration step. What it loses is the 3.11.x window, where granted_scopes is correct but original_grant is absent: those records get the permissive path, i.e. we send the caller's scopes and let the authorization server answer invalid_scope rather than refusing locally. That is a strictly better failure than "unrecoverable until re-auth".
B. A format_version: u8 (or grant_known: bool) marker with the same unknown treatment.
Same recovery for legacy records, no value to store, but it also drops the correct grant that 3.11.x records do carry, so A dominates it unless you want the version marker for other reasons.
C. Status quo: keep the local error, document that a narrowed pre-3.10.1 record needs re-authorization.
The message at :2178 is already actionable, and not weakening the error is right; this is the only option with no format change.
If you want A, I can send the PR with the two tests above (they fail on the assertions if the field is added without wiring, so they double as the regression suite). That is a maintainer call, since it changes the persisted record.
Activity
github-actions commentedon Nov 16, 2026
@michaelneale is on triage rotation this week and is the reviewer for this one.
Codex labeled this bug / P2 (T-security). Please confirm or correct those labels.
Automated triage. Labels are a first pass and the assigned maintainer has the final say.
jokemanfire commentedon Nov 19, 2026
Confirmed at
165f8fd(rmcp 3.11.0) by running it, not by reading the description. Both halves reproduce, and the first one fails before any request leaves the process.Reproduction
Two tests in
transport::auth::tests, in the style of the existingstart_token_servertests (local axum/tokenthat captures the request body). Against165f8fd:The tests pass because they assert the broken behaviour:
granted_scopes: ["read"](what 3.10.0 wrote after a narrowed refresh),set_refresh_scopes(["write"]), thenrefresh_token(). Asserted: error isAuthError::TokenRefreshFailed, and the/tokenhandler never received a body (capturedis stillNone). So the request is never sent — nothing at the server can widen it, andon_refresh_token_rejectedis not reached; the refresh token is still valid and simply unusable.granted_scopes: ["read"], no refresh scopes set, and a token response that reports"scope":"read write". Asserted: afterrefresh_token(), the stored record still says["read"]. The response is discarded for storage purposes, so the next refresh repeats case 1.Where the code does it
refresh_request_scopes(crates/rmcp/src/transport/auth.rs:2159):kept.is_empty()returnsTokenRefreshFailedat:2178-2181whenever the record'sgranted_scopesis non-empty and shares nothing with the caller's scopes.refresh_token(:2603) calls it at:2643-2644, beforerefresh_requestis dispatched, which is what thecaptured.is_none()assertion pins.stored_grant(:2706-2710):original_grantis justgranted_scopes.clone(), so a legacy narrowed value is preserved as if it were the original grant on both branches.StoredCredentials.granted_scopes(:277) is the only scope field; it is#[serde(default)], and the struct is#[non_exhaustive].Why there is no safe one-field fix for (2)
A tempting change is "when
!asked_for_subset, store the scopes the response reported". That fixes (2) for this record but regresses records where the stored value is the original grant: an unscoped refresh may still come back narrower under server policy, and the response then says less than the grant. Both populations look identical in the record, so the choice has to come from the record, not from the last response.Options
A. Add
original_grant: Option<Vec<String>>toStoredCredentials(my preference).#[serde(default)], written wherever the grant is actually known — the authorization-code exchange (:2495-2507, and the equivalent inexchange_code_for_tokenaround:3734), carried unchanged through refreshes. On read:Someis authoritative;Nonemeans unknown, which should behave like the existing unknown case inrefresh_request_scopes(:2170-2172,granted.is_empty()) and let the record be rewritten with what the response reports.Cost is lower than it looks: the struct is
#[non_exhaustive]and every field already has#[serde(default)], so old records deserialize asNoneand new records still load in an older rmcp — no migration step. What it loses is the 3.11.x window, wheregranted_scopesis correct butoriginal_grantis absent: those records get the permissive path, i.e. we send the caller's scopes and let the authorization server answerinvalid_scoperather than refusing locally. That is a strictly better failure than "unrecoverable until re-auth".B. A
format_version: u8(orgrant_known: bool) marker with the same unknown treatment.Same recovery for legacy records, no value to store, but it also drops the correct grant that 3.11.x records do carry, so A dominates it unless you want the version marker for other reasons.
C. Status quo: keep the local error, document that a narrowed pre-3.10.1 record needs re-authorization.
The message at
:2178is already actionable, and not weakening the error is right; this is the only option with no format change.If you want A, I can send the PR with the two tests above (they fail on the assertions if the field is added without wiring, so they double as the regression suite). That is a maintainer call, since it changes the persisted record.