Repository navigation
feat: warn before narrowing a self-registered OAuth2 app's scope allowlist - #29777
Conversation
…wlist Self-registered clients usually request every scope Coder advertises rather than reading the app's allowlist. Narrowing the allowlist for such an app does not narrow what the client asks for, so every new authorization fails with invalid_scope while existing tokens keep their scopes. PLAT-664 proposed refusing the change on the API. This takes the lighter route and warns instead. - Expose dynamically_registered on OAuth2ProviderApp so the UI can tell a self-registered app from an admin-created one. - Show a warning in the scope picker when an edit removes scopes from a self-registered app's allowlist. Widening and clearing stay quiet. - Add a Registration row to the app page reading Self-registered or Admin created. - Document the failure mode under Scopes and cross-reference it from the invalid_scope troubleshooting entry. Remove the stale note that the web UI cannot set the allowlist. Closes PLAT-664
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
|
/coder-agents-review |
|
Review could not be started (account spend limit) deep-review v0.9.0 | Round 3 | Last posted: Round 3, 29 findings (1 P1, 9 P2, 9 P3, 1 P4, 5 Nit, 4 Note), COMMENT. Review Finding inventoryFinding inventory: PR #29777Findings
Contested and acknowledgedCRF-9 (P3, OAuth2AppForm.tsx:271) - narrowing predicate compares names, server compares coverage
Round logRound 0 (prior session)Netero-only first pass posted in an earlier session as review PRR_kwDOGkVX1s8AAAABOx2P8Q. Local deep-review state for that round is not available, so its findings are recorded here as R0 with their original IDs (CRF-1 to CRF-7). 1 P1, 2 P2, 1 P3, 3 Notes. Round 1Netero-only (second consecutive first-pass round; the panel has not reviewed this PR). Reviewed against 528dd3c..726a5ac. Prior findings: CRF-1, CRF-5, CRF-6 verified fixed by Netero. CRF-2 and CRF-7 were fixed as prescribed, but both prescriptions conflict with FE1 ( New: 1 P2 (CRF-8), 2 P3 (CRF-9, CRF-10). 1 Note dropped (CRF-11). Orchestrator verification: FE1 text read at head. Interaction: CRF-8's fix (extract the predicate into a pure function and table-test it) is also where CRF-9's coverage cases belong, and it replaces the four render-based tests that CRF-11 observed timing out under load. Next round: the consecutive Netero-only cap (2) is reached by R0 plus R1. The CLI counts only local rounds and will not enforce it, so the next orchestrator must skip step 3a and go straight to panel selection. Round 2 updateBLOCKED. CRF-3 and CRF-4 silent for a second round (no author reply, unchanged at 40b5e0d: docs lines 812 and 862, test name at Observation: across R0 to R2 the author replied to all eight thread-anchored findings and to neither body-only finding (CRF-3 and CRF-4 sit on lines outside the diff, so CI at 40b5e0d: the Storybook job failed with a Pixel service error ( Next round: the panel is still owed and the Netero-only cap still applies, so skip step 3a and go straight to panel selection once the churn guard returns PROCEED. Round 3First panel round. Churn guard PROCEED (CRF-3, CRF-4 addressed in 488ca37; the author replied in a PR comment). Netero skipped per the consecutive first-pass cap (R0, R1). Law not triggered (212 effective additions). Panel: 25 trigger-matched (Bisky, Hisoka, Mafu-san, Mafuuu, Pariston, Chopper, Ging-Go, Ging-TS, Ging-React, Gon, Kite, Knov, Knuckle, Komugi, Kurapika, Leorio, Luffy, Melody, Meruem, Nami, Pen Botter, Razor, Robin, Ryosuke, Zoro) plus wildcards Killua and Takumi (all distilled personas were trigger-matched, so both came from the full pool). Reviewed against fd5b375..fe90c82. New: 6 P2 (CRF-12, 13, 15, 16, 17, 23), 6 P3 (CRF-14, 18 to 22), 1 P4 (CRF-24), 5 Nit (CRF-25 to 28, 34), 1 Note (CRF-29). CRF-4 re-raised. CRF-9 remainder closed by panel. 4 dropped (CRF-30 to 33). Cross-check decisions:
Orchestrator verification: Next round: churn guard, then Netero (post-panel, advisory), then a panel of at least 2-3 trigger-matched reviewers plus wildcards. Gon and Leorio are mandatory if the Alert copy, docs, or comments change, which CRF-12 to CRF-15 require. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
BobbyHo
left a comment
There was a problem hiding this comment.
First-pass review only. These are mechanical findings from a single first-pass reviewer; the full review panel has not yet reviewed this PR and will do so after these are addressed.
The framing is the strongest part of this change. "Warn instead of refuse" is the right call for a failure mode the admin can't see from the edit screen, and the docs section explains the mechanism (client requests scopes_supported, allowlist doesn't shrink the request, Coder rejects rather than trims) better than an API error ever could. The Go side is clean: the new RegistrationOrigin subtest asserts false then true across the two creation paths and cannot pass without the SDK field this PR adds.
1 P1, 2 P2, 1 P3, 3 Notes.
The P1 is that the warning does not fire in the case it most needs to. narrowsSelfRegisteredScopes requires form.initialValues.scope.some(...), and a self-registered app with no stored allowlist gives initialValues.scope === [], so the predicate is always false. An admin imposing an allowlist on an unrestricted self-registered app, which is the default shape of a DCR app that registers without a scope field, gets no warning. The docs this PR adds claim otherwise at line 356.
The P1 and the first P2 are the same defect seen twice: the only coverage of the new conditional is a Storybook play function with no assertion, and it still passes when the feature is short-circuited. A test enumerating the transitions would have caught the empty-allowlist gap.
On the reviewer's verification of that story:
I ran
pnpm vitest run --project=storybook .../OAuth2AppForm.stories.tsx: 9 passed. I then short-circuited the feature (const narrowsSelfRegisteredScopes = false && ...) and re-ran: 9 passed again. The story cannot fail when the feature is deleted.
One process note: the PR description lists "Remove the stale note that the web UI cannot set the allowlist" as an intended change, and one of the three instances was removed. The other two now contradict the text this PR adds in the same file.
docs/admin/integrations/oauth2-provider.md:812
P2 [CRF-3] Limitations still says the web UI cannot set a scope allowlist, contradicting two lines this PR adds. (Netero)
The line reads: "The web UI cannot set or change a scope allowlist; declare one at Dynamic Client Registration or set it through the management API, as described under Scopes". The PR adds "Allowed scopes: Optional." to the web UI creation steps (line 66) and "An administrator sets one with the Allowed scopes field in the web UI" (line 345). The same file now states both.
Sibling at line 862: "The web UI cannot change it.", closing the paragraph about fixing an app whose registered
scopenames unsupported values. Also false; the picker sets any name the deployment offers.The PR description lists "Remove the stale note that the web UI cannot set the allowlist" as an intended change. It removed one of three instances.
Confirmed: grep -n "web UI" docs/admin/integrations/oauth2-provider.md at head returns both 812 and 862 alongside the new 345 and 356.
The claim was already false at the base commit, but "pre-existing" does not apply here. At base the document did not contradict itself; this PR adds the opposing statement and leaves both in place, so a reader who lands on Limitations or on the DCR fix note is now told the opposite of what Scopes says three hundred lines up. Both are one-line deletions.
🤖
site/src/pages/DeploymentSettingsPage/OAuth2AppsSettingsPage/OAuth2AppForm.test.tsx:62
P3 [CRF-4] Test named "submits edited dynamically registered client values" now runs against a fixture this PR marks as not dynamically registered. (Netero)
The test builds its app from
MockOAuth2ProviderApps[0], whichsite/src/testHelpers/entities.ts:4982pins todynamically_registered: false. Before this PR the field did not exist and the name was merely vague; now it makes a claim the fixture contradicts. The test body edits the name and assertsscopeis omitted from the payload, which has nothing to do with registration origin.
Confirmed. This PR is what turns a vague name into a false one, and the name now sits next to a real dynamically_registered distinction that a future reader will assume the test covers. Rename it to what it checks (the "omit an untouched allowlist on update" case), or switch the fixture to MockOAuth2ProviderAppPublic.
🤖
🤖 This review was automatically generated with Coder Agents.
…rn when an allowlist is imposed on an unrestricted self-registered app The narrowing warning compared the new selection against the stored allowlist with `some`, which is always false when the stored list is empty. An empty allowlist means unrestricted, so imposing any list on a self-registered app that had none is the strongest narrowing and is the default shape of a DCR client that registered without `scope`. Treat a non-empty selection against an empty stored list as narrowing. Adds Vitest coverage for the empty-to-list case and for the cases that must stay silent: clearing the allowlist and editing an admin-created app.
…ope-warning # Conflicts: # site/src/pages/DeploymentSettingsPage/OAuth2AppsSettingsPage/OAuth2AppForm.tsx
|
/coder-agents-review |
…tration row The public client mock also carried dynamically_registered, so every test that picked it for the client type became a self-registered case. Add a confidential self-registered mock that differs from the admin created mock only in registration origin, and point the scope warning tests and story at it. Assert the Registration row text in both edit page stories, and correct the db2sdk comment: the column has no NOT NULL constraint, but every write path sets a value, so false is the safe read rather than a legacy NULL case.
|
Chat: Review in progress (28/28 reviewers complete) | View chat
|
There was a problem hiding this comment.
First-pass review only. These are mechanical findings from a single first-pass reviewer (Netero); the full review panel has not yet reviewed this PR and will do so after these are addressed. This is the second first-pass round, so the next round goes to the panel regardless.
The fixes from the last round landed well. The empty-allowlist case from CRF-1 now warns, and its test fails without the new clause. The CRF-5 comment now matches migration 000344. CRF-6 split the mock so registration origin and client type vary independently.
New this round: 1 P2, 2 P3. Still open from last round: CRF-3 (P2) and CRF-4 (P3).
Two corrections to the previous review. CRF-2 asked for Vitest cases without saying how to assert them, and CRF-7 prescribed a toBeVisible() assertion inside a play function. FE1 in .claude/docs/FRONTEND_PATTERNS.md calls both a hard stop, so the code written to satisfy them comes back as CRF-8 and CRF-10. That mistake is the first pass's, not yours. The underlying asks still stand (predicate coverage that can fail, both Registration states captured), and the FE1 route is a pure-function table test plus assertion-free stories.
CRF-3 and CRF-4 were only in the previous review's body, not in threads, and have no response. Both are unchanged at 726a5ac and both are small. Each needs a fix in this PR or a reply saying why it should stay.
CRF-9 is worth doing together with CRF-8: the predicate compares scope names while the server compares coverage, so widening to coder:all shows a warning that says new authorizations will fail. From Netero:
The test name says "removed", but the scope set it submits is strictly wider than the stored one.
One Netero note (intermittent timeouts in OAuth2AppForm.test.tsx under load) was dropped: the file ran 86/86 three times on a clean worktree, and the failures Netero saw hit tests this PR does not touch.
In reply to PRR_kwDOGkVX1s8AAAABOx2P8Q:
P2 [CRF-3] Still open at 726a5ac, with no response yet. docs/admin/integrations/oauth2-provider.md:812 still reads "The web UI cannot set or change a scope allowlist", and :862 still reads "The web UI cannot change it." Both contradict :345 and :356, which this PR adds, so a reader landing on Limitations or on the DCR fix note is told the opposite of what Scopes says. This finding was in the previous review's body rather than a thread, which may be why it was missed. Needed: fix both lines in this PR, or reply with why they should stay.
🤖
In reply to PRR_kwDOGkVX1s8AAAABOx2P8Q:
P3 [CRF-4] Still open at 726a5ac, with no response yet. OAuth2AppForm.test.tsx:70 is still named "submits edited dynamically registered client values" and still builds its app from MockOAuth2ProviderApps[0] (dynamically_registered: false). With MockOAuth2ProviderAppDynamic now defined next to it, a reader will assume this test covers self-registered apps. The body checks the update payload after a name edit: the name is trimmed, and the untouched redirect URIs and allowlist are omitted. Needed: rename it to what it checks, or reply with why not.
🤖
🤖 This review was automatically generated with Coder Agents.
…tract the scope narrowing predicate and stay quiet for coder:all The warning compared scope names, but the server compares what scopes grant, so replacing a scope with coder:all showed a warning on a widening. Extract narrowsAllowlist as a pure function that treats a list containing coder:all as never narrowing, and keep the self-registered gate at the call site. Replace the render tests, which asserted DOM presence against FE1, with a table test on the predicate. Add a widening story for the quiet state and drop the play assertions on the Registration row, which the screenshots already capture.
|
/coder-agents-review |
There was a problem hiding this comment.
Review blocked. Two findings from earlier rounds have gone two rounds with no fix and no reply, so the full panel review is on hold until each gets one.
Both sit on lines outside the diff, so neither has a comment thread; they have only appeared in review bodies. Each needs a fix pushed to this PR, or a reply (a PR comment is fine) saying why it should stay:
- P2 CRF-3,
docs/admin/integrations/oauth2-provider.md:812and:862. Line 812 says "The web UI cannot set or change a scope allowlist" and line 862 says "The web UI cannot change it." Both contradict:345and:356, which this PR adds. Deleting or rewriting the two lines resolves it. - P3 CRF-4,
site/src/pages/DeploymentSettingsPage/OAuth2AppsSettingsPage/OAuth2AppForm.test.tsx:69. The test is named "submits edited dynamically registered client values" but builds fromMockOAuth2ProviderApps[0], which is admin created. Renaming it to what it checks (the update payload after a name edit) resolves it.
CRF-8, CRF-9 and CRF-10 have replies and a fix in 40b5e0d; the panel will verify them when the review resumes.
The failing Storybook check is a Pixel service error (ApiError: HTTP 500, api key lookup failed) raised while creating the Pixel build, before any snapshot comparison. It is not caused by this PR.
🤖 This review was automatically generated with Coder Agents.
Two lines in the OAuth2 provider docs still said the web UI cannot set or change a scope allowlist, contradicting the Scopes section this PR updated. Drop the Limitations bullet and point the fix paragraph at the Allowed scopes field. Rename a form test that claimed to cover a dynamically registered client but builds from the admin created mock. It checks the update payload after a name edit.
|
CRF-3 and CRF-4 are fixed in 488ca37. The Limitations bullet is removed and the fix paragraph now points at the Allowed scopes field. The test is renamed to "submits only the changed fields when a name is edited". |
|
/coder-agents-review |
There was a problem hiding this comment.
First full panel review (27 reviewers). The core of this PR holds up. narrowsAllowlist is a pure function whose table test fails when any branch is removed. dynamically_registered is written on every create path, and neither admin updates nor client updates change it. The RegistrationOrigin test goes through the real DCR endpoint. CRF-3, CRF-8 and CRF-10 are verified fixed. The panel closed the CRF-9 remainder: the name comparison can over-warn but never miss a real narrowing, and the UI has no coverage data to do better.
6 P2, 6 P3, 1 P4, 5 Nit, 1 Note, plus CRF-4 re-raised (the new test name also misdescribes what the test asserts).
Most of the P2s are about what the PR tells the admin, not what the code does. Sixteen reviewers independently caught the same contradiction: the docs say these clients request every advertised scope, then advise re-registering with fewer scopes, which cannot change what such a client requests (CRF-12 in the docs, CRF-13 in the warning). Coder's own MCP client works this way (coderd/mcp.go:2065). The code comment at OAuth2AppForm.tsx:284 states the other model, the only one under which that advice works (CRF-15). Separately, Kurapika and Pariston each reproduced that a client's RFC 7592 update overwrites or clears an admin-narrowed allowlist, and the new paragraph does not say so (CRF-16). Taken together, the PR gives admins no working way to restrict a self-registered client while implying two. The docs fix is small. The server-side fix (an admin-owned ceiling the client cannot overwrite, or granting the covered subset instead of rejecting) changes behavior and needs a human decision: file a ticket or accept the gap explicitly.
CRF-17 is the one functional bug. The predicate compares raw stored names, so removing an unsupported name, which is the repair this PR's docs now point admins to at line 861, shows a warning that the repair will break the app.
From Ryosuke:
Right now the admin and the client drive the same car from different seats. Each can overrule the other, and neither sees what the other did.
The PR comment answering CRF-3 and CRF-4 is what unblocked this round.
In reply to PRR_kwDOGkVX1s8AAAABO42LAg:
P2 [CRF-23] PR description: the Verification table describes a tree three fix commits old, "Widening and clearing stay quiet" is still stated after the author acknowledged a widening that warns, and the description never says why this PR warns instead of refusing. (Mafu-san P2, Leorio P3)
The table says "Form unit tests: 66 passed". At head the file has 89 tests, and all 89 pass (run above). [...] "Story tests: not run locally, Playwright could not launch a browser" was an honest disclosure at the time. The stories do run in this worktree (21 passed), so the gap could have been closed. (Mafu-san)
It says "PLAT-664 proposed refusing the change on the API. This PR warns instead." and never says why. A reviewer can't get that from the diff, and it's the decision this whole PR rests on. (Leorio)
Mafu-san suggests: "Adding scopes and clearing stay quiet; replacing a scope with a broader one other than coder:all still warns." CRF-16 bears on the missing rationale: refusing on the API would not hold either, because the client can rewrite the allowlist.
🤖
coderd/oauth2provider/tokens.go:64
P4 [CRF-24] The checkScopeStillCovered doc comment says "Only the client can change them, through its RFC 7592 registration", while this PR documents admins changing the same allowlist. (Melody P4, Leorio P3)
The runtime behavior is correct. An admin who narrows the list while a code is still outstanding causes an
errStaleScoperedemption failure, which the recheck handles. Only the comment is wrong. A later reader will assume the recheck only covers changes made by the client. (Melody)
Rated P4 because the admin update path and the Allowed scopes field predate this PR, so the comment was already stale. Leorio's one-line fix: "The client can change them through its RFC 7592 registration, and an administrator through the management API or the web UI."
🤖
In reply to PRR_kwDOGkVX1s8AAAABO42LAg:
Nit [CRF-28] PR title: feat: warn before narrowing a self-registered OAuth2 app's scope allowlist is 74 characters, and docs/about/contributing/CONTRIBUTING.md:282-283 says "no more than 72". (Leorio)
The squash-merge commit gets this title. Suggestion:
feat: warn before narrowing a self-registered OAuth2 app's scopes(65). (Leorio)
🤖
🤖 This review was automatically generated with Coder Agents.
…allowlist Re-registering a client does not change what it requests, and the admin cannot re-register a client they do not operate. Say instead that a client requesting every advertised scope cannot be restricted through its allowlist, and that the registration token holder can replace or clear an admin-set allowlist at any time. Shorten the form's warning to the failure and a link to the Scopes section, so the explanation lives in one place, and point the code comment at the same section.
…' into bobby/plat-664-dcr-scope-warning
…nore scope names the deployment does not offer when warning about narrowing The server drops names outside the scope catalog before comparing an allowlist to a request, so removing such a name changes nothing. The warning compared raw names and told an admin following the documented repair that the fix would break the app. A whitespace-only stored value was also read as unrestricted, although the server treats it as a list that grants nothing. Give the predicate the loaded catalog and the raw stored value, filter both sides to offered names, and treat a stored list that grants nothing as one any list can only widen.
…capture an admin-created app narrowed without the scope warning The self-registered gate on the warning had no story or test that would change if it were removed. Add a story that narrows an admin-created app's scopes so the quiet state is in the screenshots.
…arning Move the registration origin test beside its sibling and assert the flag survives an admin update. Derive the self-registered mock from the admin created one, mark the existing DCR values story self-registered instead of adding a second story, and hyphenate Admin-created. Type the coder:all literal, state which way the narrowing predicate errs, and say what a NULL registration flag hides.
dylanhuff-at-coder
left a comment
There was a problem hiding this comment.
Two comments on the scope warning, lgtm tho :)
…en the scope warning docs link in a new tab The warning only shows while the scope edit is unsaved. Navigating the current tab to the docs triggered the leave-page prompt, and continuing dropped the edit. The link now opens in a new tab and carries a visually hidden cue for screen readers, matching the navbar support links.
…over swapping one allowed scope for another The table had rows for removing a scope and for replacing one with coder:all, but none where the list stays the same length while its contents change. A length-only check would have passed every row.
Closes PLAT-664.
Self-registered clients usually request every scope Coder advertises rather than reading the app's allowlist. Narrowing the allowlist for such an app does not narrow what the client asks for, so every new authorization fails with
invalid_scopewhile existing tokens keep their scopes. PLAT-664 proposed refusing the change on the API. This PR warns instead.dynamically_registeredon the OAuth2 app response so the UI can tell a self-registered app from an admin-created one.invalid_scopetroubleshooting entry. Remove the stale note that the web UI cannot set the allowlist.Based on
main. Independent of the PLAT-619 stack (#29603).Verification
go vetManual Tests
Scenario summary, 26 of 27 pass
Run on 2026-09-23 against a dev server built from
980355459d. The later head,54380ef8a8, only mergesmainand changes none of this PR's files.owner; the four scope names used below are advertisedfalse)dynamically_registeredon list and single-app responses:truefor the three DCR apps,falsefor the admin app, always a booleanPUTthat omitsscopekeeps the flag and the allowlistAdmin-created, plain text, no copy buttonSelf-registeredSelf-registered, secrets table still shown#scopes, Update enabledcoder:all: no warningcode=Self-registeredinvalid_scopecode=code=5c is a test design issue, not a bug. The narrowing used in 3b and 5b removes
workspace:sshand keepscoder:workspaces.access, but that composite already grants workspacessh, and the authorize endpoint compares coverage, not names. So the request was granted. The warning on that edit is the over-warningnarrowsAllowlistdocuments: it cannot see coverage beyondcoder:all, so it can warn about a change the server accepts, but never stays quiet about one it rejects. A real narrowing would drop coverage, for example keepworkspace:sshand removecoder:workspaces.access.Setup and verification commands
The dashboard on
:8080drives every UI scenario from a browser. The API on:3000is used for seeding, read-backs, and the authorize calls, through acoder port-forward ... --tcp 8080:8080 --tcp 3000:3000tunnel. The session token is read inside the workspace on each call.A redirect carrying
code=means the scope was granted;error=invalid_scopemeans the allowlist refused it.UI scenarios were checked by reading the page before each capture: the Allowed scopes chips, whether an element with
role="alert"mentioning "self-registered client" exists, and thedisabledstate of Update application.0. Prerequisites and seed data
Seeded four apps, each
HTTP 201:1. API field
The flag follows how the app was registered, not its client type: both confidential apps are present and only the DCR one is
true.1b, admin
PUTwithoutscope:2. Registration row
Read from the details list on each edit page:
Client ID, Authorization URL, and Token URL each keep their
<code>value and copy button; the Registration row is last and plain text.3. Warning in the scope picker
All on
plat664-dcr-scoped(storedcoder:workspaces.access workspace:ssh) unless noted. Nothing in this section was saved.3b warning, read from the page:
The link has no
/@v<version>segment here because the page was served by Vite, which does not carry the server-rendered build info thatdocs.tsreads. The path and anchor are correct.In 3e the warning showed on the way down at one chip and cleared at zero, since an empty allowlist means unrestricted.
4. Names the deployment does not offer
4a and 4b, with an unknown name planted through the admin API:
4c, whitespace-only allowlist:
Same edit as 3g with the opposite result:
" "is a configured list that grants nothing, so adding a scope widens it. Both apps were restored afterwards androwsmatched the seed output.5. Authorize before and after narrowing
Why 5c was granted, from
coderd/rbac/scopes.go:negotiateScopeaccepts a request once the allowlist covers every requested name, socoder:workspaces.accessalone still coversworkspace:ssh.6. Docs
Against
docs/admin/integrations/oauth2-provider.mdin the checkout:The narrowing paragraph no longer tells the admin to re-register the client; it says only a client that can be configured to request fewer scopes can be narrowed, by whoever operates it. It also says a client "may then request anything that allowlist covers", which matches the 5c result.
7. Cleanup
The apps were deleted through the admin API rather than the edit page's Delete button.
Apps table back to "No OAuth2 applications configured"; DCR back to its starting value.