Skip to content

feat: accept redirect_uris on the OAuth2 app admin API and deprecate callback_url - #29502

Merged
BobbyHo merged 58 commits into
mainfrom
plat-619-2-api
Sep 22, 2026
Merged

BobbyHo merged 58 commits into
mainfrom
plat-619-2-api

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Second of three in PLAT-619. #29440 made redirect_uris the source of truth in the database. This PR exposes it on the admin API.

PR What it does
#29440 Backfill the list, read only from it, write both columns together, validate and cap every entry.
this Accept and return redirect_uris on the admin API. Mark callback_url deprecated.
#29603 Edit the list in the admin UI.
  • Add redirect_uris to the app response and the create/update requests.
  • callback_url still works but is deprecated. It equals the first entry.
  • Fix a bug where an empty redirect_uris list was silently ignored instead of rejected.
  • Update fixtures, tests, and docs for the new field.

Stack: #29440 (this branch is based on it), then this PR, then #29603 (UI).

Editing an app's callback added a new accepted URI without removing the
old one, and the admin API only showed the callback (PLAT-619, SEC-870).

- Backfill every row so the callback is the first redirect URI. The
  migration handles empty, missing, and out-of-order lists and is safe
  to rerun. The callback column is kept, marked deprecated.
- Read redirect URIs from the list only. A callback that is not in the
  list is no longer accepted.
- Write both columns together from one shared function. A callback-only
  update now replaces the previous primary and keeps the rest.
- Validate every entry the same way as the callback.
- Cap the list at 32 entries of 2048 bytes each, including at
  registration.

No existing request or response changes shape.
… app update

- Admin updates re-checked the whole stored list against the new caps.
- Apps registered before the caps with over 32 URIs, or a URI over 2048 bytes, could not be edited at all.
- Only URIs the request adds are checked now. The count cap applies only when the list grows.
… redirect URIs

- An old replica writes only callback_url on an admin update.
- New replicas read redirect_uris first, so that edit is not seen until the app is saved again.
- Drain old replicas before upgrading to avoid it.
…de window

- redirect_uris is now the source of truth, with the primary first.
- During a rolling upgrade, a callback edit on an old replica is not seen by new replicas until the app is saved again.
- An app may register at most 32 redirect URIs of at most 2048 bytes each. Older apps beyond that keep working.
- Covers all four documented input shapes, plus dedup and callback ordering.
- The doc comment notes that the list-with-callback and neither shapes get their caller when the admin API gains redirect_uris in the next PR.
…he callback field

- A failure on the request callback_url now says "callback URL ..." with no list index.
- List entries keep the indexed wording for registration callers.
…lidation

- The shape check now rejects fragments, so admin and registration store the same rules.
- Rename ValidateOAuth2CallbackURL to ValidateOAuth2RedirectURIShape and the local validator to validateAppRedirectURIFields.
- The column comment says "first entry of redirect_uris" instead of a 1-based index.
- RegisteredRedirectURIs documents that it is never empty.
- Test that registration stores a deduplicated list. Use plain numbered test URIs.
- ValidateRedirectURI now rejects hostless http(s) and opaque URIs for every client type.
- Move the shared rules into a helper so both paths use one copy.
- Test that ValidateRedirectURI rejects everything the shape check rejects.
…upgrade

- The doc bullet and migration comment said the edit was "not visible".
- They now say it is silently discarded and the app keeps accepting the previous redirect URIs until saved again.
- Drop the forward reference to the next PR from the resolveRedirectURIs doc.
- Let the public client rejection message stand on its own instead of repeating "public client".
- Remove the oauth2_callback_url struct tag. It ran the shape check first and failed with a generic tag message.
- The handler already runs the same check and names the reason against callback_url.
- Test that a callback with a fragment reports that reason.
…pdate itself

- The RFC 7592 update path validated the full resent list with no stored context, so a legacy over-cap client could not save any change.
- It now skips redirect URIs the client already has and applies the count cap only when the list grew, matching the admin path.
- Create still enforces the caps on every entry.
- Remove the duplicated ValidateRedirectURIScheme doc comment.
- Legacy clients may store duplicates, and the stored baseline is deduplicated.
- Resending the list as returned no longer reads as growth.
- Stored redirect URIs are checked again on every update, with no exception for apps that predate the caps.
- An app over the limits must be deleted and created or registered again.
- Remove the duplicated ValidateRedirectURIScheme doc comment again.
…hority

- Registration accepted the bare scheme:value form before this change.
- Add test cases for the three private-use forms.
- Rename ValidateOAuth2RedirectURIShape to ValidateRedirectURIShape to match its siblings.
- Scheme errors no longer start with "redirect URI", since every caller adds its own subject.
…callback_url

- Add redirect_uris to the app response and the create/update requests.
- callback_url still works but is deprecated; it equals the first entry.
- Fix a bug where an empty redirect_uris list was silently ignored instead
  of rejected.
- Update fixtures, tests, and docs for the new field.
@linear-code

linear-code Bot commented Sep 17, 2026

Copy link
Copy Markdown

PLAT-619

…keeps

The request and response comments named Go identifiers such as
RedirectURIs[0], which mean nothing to an HTTP caller reading the
generated API reference. The PUT comment said omitting both URI fields
keeps the stored list, which read as a partial update when icon is
cleared if omitted.

- Refer to redirect_uris and callback_url by their JSON names.
- Say that omitting both keeps only the redirect URIs and other fields
  are replaced.
- Note that an empty slice is dropped by omitempty and keeps the list.
- Drop the duplicate "send this instead" sentence from redirect_uris.
…fy the admin edit claim

- Drop the Limitations paragraph about redirect_uris on the management
  API. The Management API section already says the same thing next to
  the example a script author copies.
- Say that the admin PUT validates the stored name, so a self-registered
  client whose name has surrounding whitespace can only be updated with
  its registration access token.
- Move the create that sends neither URI field out of EmptyListIsRefused
  into its own subtest, since it is not an empty list.
- Name the resolver rows for what the function returns. The rejection
  happens in validation, not in the resolver.
- Compare the resolver result unconditionally instead of by length only
  when the expected list is empty.
@BobbyHo

BobbyHo commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review re-review the P2 and P3 reported in the last review. Only report if there are more P0 to P3.

1 similar comment
@BobbyHo

BobbyHo commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review re-review the P2 and P3 reported in the last review. Only report if there are more P0 to P3.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review blocked. No panel ran this round.

The work since round 3 is substantial and mostly at the root: 28 of 34 findings are addressed across twelve commits. validateRedirectURIFieldsAgree plus a resolver that now returns slice.Unique(redirectURIs) with no delete-and-prepend closes the P1 (CRF-10) and, with it, the index shift in CRF-13 and the shape behind CRF-17. UpdateApp running inside db.InTx with a new GetOAuth2ProviderAppByIDForUpdate closes the lost update (CRF-12), with RenameKeepsConcurrentRedirectURIChange to hold it. ListCap and the new detail assertions close CRF-18 and CRF-19, GetClientConfiguration now reads through RegisteredRedirectURIs() with a test that writes a duplicate and asserts both endpoints agree (CRF-30), and the docs section gained the PUT example with the name-required and icon-cleared caveats stated out loud (CRF-15, CRF-28). I verified the two headline fixes in the tree rather than from the commit messages.

Four findings from the last review have no code change, no reply, and no linked ticket:

  • CRF-2 (P2), codersdk/oauth2.go:94 and :124. Both tags still read redirect_uris,omitempty. No omitzero, no *[]string, no rejection of the omit-both shape. The panel refuted this defense's premise in round 3 with three verified alternatives and the thread has had no reply since. 11e55a95ab documents the gap ("An empty slice is omitted on the wire, so it also keeps the stored list") rather than closing it, which was CRF-33's ask, not this one. Third round carrying a deferral to an unlanded PR with nothing tracking it.
  • CRF-14 (P2), coderd/oauth2provider/apps.go:110-112. Still if clientType != codersdk.OAuth2ClientTypePublic { continue }, so the admin API accepts cleartext http:// redirect targets for confidential apps that dynamic registration refuses for the same client type, now across up to 32 entries. Round 3 said explicitly that this needs a human decision: validate every client type, or record why an admin may store what a client may not register for itself. Either answer closes it; silence does not.
  • CRF-16 (P2), coderd/oauth2provider/authorize.go:625. Still "The application's registered callback URL is not usable." while the docs half of that pair moved to the plural in round 3. The file is absent from your diff.
  • CRF-31 (P3), EditOAuth2AppPageView.stories.tsx:166. Still overrides callback_url with no matching redirect_uris, so the fixture violates the invariant this PR documents.

On the process rather than the code: CRF-14, CRF-16 and CRF-31 all landed on lines outside the diff hunks, so the tool folded them into the round-3 review body and they never became threads you could resolve. That is a known way for findings to get lost and it is not on you; it is why they are named individually above. CRF-2 is the different case, since its thread carries the refutation.

Two more items to note, neither blocking:

  • CRF-11 is accepted on "the two will ship in the same release, so there is no build where the API accepts multi-URI apps that the UI cannot display." That is a release-coordination claim, and nothing in the repository can confirm it: it holds only if no release is cut between this merge and the UI PR's merge. Link the issue or milestone that couples them and the acceptance becomes checkable.
  • Two residues the panel will verify next round rather than now: deduplication still reindexes, so a duplicate ahead of a bad entry still shifts the index in the message (CRF-13), and the value-match closure at apps.go:82-84 is unchanged, so a failure on the primary of an agreeing both-fields request is still reported against callback_url (CRF-17).

Your two comments asking to re-review the P2s and P3s and to report only new P0 to P3 items: understood, and that is what this round did. All four findings above were in the last review, so they are inside that scope. Reply with a fix, a ticket, or a reasoned rejection for each, and the panel runs on the next round.

🤖 This review was automatically generated with Coder Agents.

The admin API rejects an explicit empty redirect_uris, but the SDK request
types tagged the field omitempty, so encoding/json dropped an empty slice
before it reached the wire. The server saw no field at all and kept the
stored list, which is the silent no-op this API change set out to remove.

omitzero drops only the zero value, which for a slice is nil. Omitting the
field still keeps the stored redirect URIs, and an empty slice now reaches
the rejection. redirect_uris stays optional in the generated TypeScript and
swagger requiredness does not move, so the app edit forms are unaffected.

EmptyListIsRefused now calls PutOAuth2ProviderApp instead of building a raw
request body, so the rejection is covered on the path SDK callers take.
The admin API ran only the shape check for confidential apps, so it accepted
cleartext http targets that dynamic client registration refuses for the same
client type. Nothing re-checks the scheme when a code is issued.

- Run ValidateRedirectURI for every client type. Only non-localhost cleartext
  http is rejected; native schemes, the OOB URN, loopback and .localhost
  subdomains still pass. The shape check runs first because it names the more
  specific reason for a malformed URI.
- Document the rule for both client types, with an upgrade note: stored URIs
  are checked again on every update, so an app holding a cleartext target
  cannot be saved until its list is corrected.
- Mirror the rule in the admin form, which applied it to public clients only
  and would otherwise accept values the server now rejects.
- Move fixtures off cleartext non-localhost hosts. The scheme-mismatch case in
  TestOAuth2ProviderTokenExchange now rewrites the registered URL to http,
  because rewriting it to https no longer changes it.
@BobbyHo

BobbyHo commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

CRF-14: fixed in db8013f, by validating every client type rather than documenting the asymmetry.

Any of up to 32 registered entries can fail, but the consent page, the API
error, and the log all said "callback URL", which sends an operator to the
entry least likely to be at fault. The docs half of that pair was already
plural.

- Report "One of the application's registered redirect URIs is not usable"
  on both the consent page and the POST error, retitle the page to Invalid
  Redirect URI, and move the @failure 500 descriptions with them.
- Wrap the scheme error with the URI so the log narrows to one entry. The
  parse case already named the offender; the scheme case did not.
- Rename logCorruptCallback and the corruptCallback field to match, since
  their comments described a parse failure on the primary entry.
- Add the matching redirect_uris to the two fixtures that override
  callback_url alone, a shape the API cannot return.
@BobbyHo

BobbyHo commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

CRF-16 and CRF-31: both fixed in 7c57cee. Neither has a thread, so this answers them here.

…of-truth' into plat-619-2-api

# Conflicts:
#	site/src/pages/DeploymentSettingsPage/OAuth2AppsSettingsPage/OAuth2AppForm.test.tsx
@BobbyHo

BobbyHo commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review re-review the P2 and P3 reported in the last review. Only report if there are more P0 to P3. If no blocking issue, please remove the "request changes" label

@BobbyHo
BobbyHo marked this pull request as ready for review September 21, 2026 20:47

@dylanhuff-at-coder dylanhuff-at-coder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The list replacement and deprecated callback path look sound. Two non-blocking suggestions for the legacy HTTP case: surface its form error and pin the documented upgrade behavior.

Comment thread coderd/oauth2provider/provider_test.go Resolved
Base automatically changed from plat-619-1-redirect-uris-source-of-truth to main September 22, 2026 17:49
…ow the error for a stored callback that fails validation

The form now rejects a cleartext http callback to a non-local host for
every client type. Confidential apps could store one before this check
existed. Opening such an app disabled Update on load, but the shared
field helper hid the callback error until the field was touched, so an
admin who only changed the name saw a disabled button with no reason.

Mark the callback field as touched from the start when the stored value
fails validation, so its error shows right away. Add a test for that
case and one that checks a valid stored callback still shows no error.
…cross authorize and update

A confidential app could store a non-local http callback before the
admin path checked the scheme. Add a test that such an app still
authorizes, that a rename omitting both URI fields is refused because
the stored list is checked again, and that replacing the list with
https entries repairs the app.
@BobbyHo
BobbyHo enabled auto-merge (squash) September 22, 2026 19:10
@BobbyHo
BobbyHo merged commit 9fd0131 into main Sep 22, 2026
31 checks passed
@BobbyHo
BobbyHo deleted the plat-619-2-api branch September 22, 2026 19:12
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants