Repository navigation
A client had to be refused before it could learn what to ask for - #89
Merged
Merged
Conversation
fold's protected-resource metadata named the authorization server but not the scopes, so a client's only route to a scope requirement was to be denied by it: authorize with whatever it guessed, connect, call a tool, and read the answer out of the -32042 error. The denial carries a remedy now, which helps the second attempt; this is about the first. scopes_supported is published in the RFC 9728 document — every scope the policy rules name, deduplicated and sorted so the document is stable between fetches. RFC 9728 §2 recommends the field for exactly this. It is a hint rather than a contract: holding all of them entitles a caller to nothing on its own, since scopes are one gate among several and a rule can also require an identity, an issuer, or a claim. Tenant selector scopes are deliberately excluded, and the first version of this published them. Two reasons, either sufficient. The endpoint is unauthenticated and a tenant scope is usually a customer's name, so a deployment selecting tenants that way would have served its customer roster from a well-known URL — a different class of secret from a capability name, and one fold does not otherwise disclose, since a denial already refuses to name a requirement to a caller who failed on other grounds. And a tenant scope is an identity assertion rather than a permission, so an authorization server asked for one will not mint it: publishing it would have leaked something real in exchange for advice no client could act on. The document is now built per request rather than marshalled once at startup. Policy hot-reloads, and a construction-time copy would have gone on advertising the rules fold started with. It costs one small marshal on a path that does no I/O and no crypto. Two things fixed while in here, both pre-existing and both reached only with EMA enabled, where the document is hand-written to carry the extension key the SDK's type cannot: it went out with no CORS headers, so a browser client's cross-origin discovery fetch failed the check; it answered a preflight with the document instead of 204; and it answered POST. The branch now matches the contract the SDK handler sets around the body, which is the part that was never EMA's to change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
blakebauman
force-pushed
the
feat/advertise-required-scopes
branch
from
August 26, 2026 01:22
044b143 to
0dd5699
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by standing a gateway up with
auth.mode: "required"and walking the chain a real client walks — 401 →WWW-Authenticate→ RFC 9728 document →authorization_servers— rather than reasoning about it.fold's half of that chain is correct. What is missing is one field.
The gap
The protected-resource document named the authorization server but not the scopes. So a client's only route to a scope requirement was to be denied by it: authorize with whatever scopes it guessed, connect, call a tool, and read the answer out of the
-32042error.#87 made that denial carry a remedy, which helps the second attempt. This is about the first.
scopes_supportedis now published — every scopepolicy.rules[].subjects.scopesnames, deduplicated and sorted so the document is stable between fetches. RFC 9728 §2 recommends the field for exactly this. Verified live against a running gateway:It is a hint rather than a contract: holding all of them entitles a caller to nothing on its own, since scopes are one gate among several and a rule can also require an identity, an issuer, or a claim.
Tenant scopes are excluded — and the first version of this published them
Worth reviewing, because it was nearly a leak.
The endpoint is unauthenticated, and a tenant scope is usually a customer's name. A deployment selecting tenants that way — fold's own flagship config has tenants
acmeandglobex— would have served its customer roster from a well-known URL. That is a different class of secret from a capability name likedocs:write, and one fold does not otherwise disclose: a denial already refuses to name a requirement to a caller who failed on other grounds (TestDenialForAnotherReasonDisclosesNoScope).The second reason is independent and equally sufficient: a tenant scope is an identity assertion, not a permission. An authorization server asked for
tenant:acmewill not mint it. Publishing it would have leaked something real in exchange for advice no client could act on.The tests pin the exclusion at the boundary that would regress — a scope named only by a tenant is absent, while the same scope named by a rule as well still appears.
Reload
The document was marshalled once at startup. Policy hot-reloads, so a construction-time copy would have gone on advertising the rules fold started with. It is built per request now — one small marshal, no I/O, no crypto. Confirmed by SIGHUP against a live gateway before writing the test, and the test mutation-checks it: restoring the old behaviour fails that test and only that test.
Two pre-existing bugs fixed while in here
Both reachable only with EMA enabled, where the document is hand-written to carry an extension key the SDK's type cannot express. The body was EMA's to change; the contract around it was not:
Access-Control-Allow-Origin*So with EMA on, a browser-based client's cross-origin discovery fetch failed the CORS check outright. Now matches the SDK handler.
Verification
go test -race ./...green; lint 0 issues; gofmt / vet / tidy cleanrequiredScopes(nil snapshot, nil cfg, unsorted input across rules and tenants, dedup, tenant-only exclusion), assertingnilrather than[]string{}for the empty cases since that is what makesomitemptydrop the keymap[string]anyround-tripresource_metadataout of theWWW-Authenticateheader and fetches it as given, so the pointer is proven followable rather than assumedContext on the adoption question this came from
Also confirmed while probing, and it corrects something I said earlier:
oauth.work— the IdP behind fold's own enterprise deployment — publishesregistration_endpoint, so it does support dynamic client registration. The DCR gap is real only for IdPs that lack it (Okta, Entra typically), not for fold's own stack.docs/configuration.mdnow states the discovery chain, what completes it, and where it does not, which is the failure mode where an operator configures fold correctly and the problem is upstream of it.🤖 Generated with Claude Code