Repository navigation
fix(refusals): treat a 403 about the resource or the account as Cloudflare's own error - #365
Merged
Merged
Conversation
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.
A 403 now counts as a permission refusal only when Cloudflare's errors say the credential was refused. Before, every 401 and 403 got a permissions explanation, and could trigger an
insufficient_scopestep-up. Fixes #364.I measured what Cloudflare sends with a throwaway API token that could only read account settings:
10000: Authentication error10000: Authentication error9109: Unauthorized to access requested resourceNo access to the specified resource.(no code)The 403s that aren't about the credential carry their own codes: Zaraz
403: Forbidden: workflow is not preview, Images5403on an account without the subscription, Workers for Platforms10121, SSL for SaaS1404.So a 401 is still always a refusal. A 403 is one when its body has no errors, when an error has code
10000or9109, or when an error has no code. A 403 whose errors all carry other codes now passes through as Cloudflare's own error, with no explanation and no step-up. Forexecute,GlobalOutboundnow reads a 403's body to decide; 403 bodies are small.Tests cover the Zaraz and Images answers in
executeand the endpoint tools: with and without the scope, plus a mixed5403and10000answer, which still refuses. Three of them fail without the change.Why the status is mixed: the edge API gateway (
cloudflare/api/gateway) answers every authorization failure with 40110000(src/middleware/auth.ts), and the core gateway answers 403. In production the edge serves KV, D1, Workers AI, Browser Rendering and Workflows, the five products that answered 401 above. The gateway's other errors are 40310000for dashboard sessions and 4047000, so every credential refusal from either gateway carries10000or9109, and this rule keeps all of them. The proposed move to 403 (wiki) keeps10000, so it needs no change here.Because of that, the second commit also changes what a 401 says when the connection already holds an accepted scope. It used to say Cloudflare rejected the credential and to reconnect. From the edge gateway it is usually the user's role, so it now says a 401 can mean either, and to reconnect only if other requests fail with 401 too.
The third commit fills two gaps in how
executeexplains missing permissions:data: null, whichexecutereported as a plain GraphQL error. Measured with a token without analytics permissions, a zone dataset says "does not have permission 'com.cloudflare.api.account.zone.analytics.read'", and an account dataset says "authorization denied". The sandbox now marks those two errors, and the host explains them as a refusal of Analytics Read or Account Analytics Read. For an OAuth connection missing the scope, it steps up foranalytics.readoraccount-analytics.read. GraphQL POSTs count as reads for replay safety, since the API has no mutations. Other GraphQL errors are unchanged.account_idargument. When code puts an account the session can't use straight into a refused request's path, the error now names the session's accounts.