8000 Pass redirect_uri in organization invite registration link by Praiztl · Pull Request #55428 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Pass redirect_uri in organization invite registration link - #55428

Open
Praiztl wants to merge 3 commits into
keycloak:mainfrom
Praiztl:fix/55412-org-invite-redirect-uri
Open

Praiztl wants to merge 3 commits into
keycloak:mainfrom
Praiztl:fix/55412-org-invite-redirect-uri

Conversation

@Praiztl
@Praiztl Praiztl commented Nov 21, 2026
Copy link
Copy Markdown

Closes #55412

Decisions and assumptions:

  • The registration link reuses invitationTarget.redirectUri, which is already resolved and validated against the client and is the same value stored in the token's reduri, so no new validation is added.
  • redirect_uri is only appended when it is non-blank, so the link stays the same for clients that resolve no redirect URI.

This change was prepared with the help of an AI agent (Claude Code).

@vramik vramik 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.

Thank you @Praiztl for the PR! Correct fix.

The production code change is sound. The redirect URI passed in the query string is the same value already resolved and validated by resolveRedirectUri() at invitation-creation time. At registration time, AuthorizationEndpointChecker.checkRedirectUri() re-validates it against the client's redirect URIs via RedirectUtils.verifyRedirectUri(), so there's no open redirect risk. The StringUtil.isBlank guard is appropriate — resolveRedirectUri() throws for non-account clients if resolution fails, but the guard handles the account-client edge case cleanly.

Few nits:

  • The fix always appends redirect_uri when it's non-blank, even for clients with a single redirect URI where the existing getSingleValidRedirectUri fallback already works. This is harmless — the endpoint validates it either way — but it means existing registration links now carry a parameter they didn't before. Not a problem in practice; just noting it's a behavior change for the common case too.
  • The test registers cleanup for INVITEE_EMAIL users, but it only opens the registration page without completing registration — so the user is never created. The cleanup is defensive and harmless, but it's slightly misleading. This is fine as-is; just calling it out.
  • the test verifies the link parameters and that the registration page loads, but doesn't complete registration. This is acceptable scope since testRegistrationConsumesInvitation already covers the full flow. However, completing registration in this test with a multi-redirect client would give stronger confidence that the redirect after registration also works correctly. Worth considering but not blocking.

Since the PR is still draft, I was wondering whether you still plan to make some changes to it, or whether it could be marked as ready for review.

@Praiztl
Praiztl marked this pull request as ready for review November 27, 2026 10:29
@Praiztl
Praiztl requested a review from a team as a code owner November 27, 2026 10:29
8000 Copilot AI balanced review requested due to automatic review settings November 27, 2026 10:29
Copilot AI 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.

🟡 Changes recommended

The unvalidated client base URL can cause previously working registration invitations to fail with invalid_redirect_uri instead of preserving the valid single-URI fallback.

1 open issue
What changed in this PR

Addresses #55412 by including the resolved redirect URI in organization invitation registration links, allowing the registration endpoint to handle clients with multiple allowed redirect URIs.

Changes:

  • Adds redirect_uri to registration links when the resolved value is nonblank.
  • Adds an integration test checking the link parameters and successful navigation to the registration page.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​organization/​admin/​OrganizationInvitationTokenTest.java Tests invitation registration links for a client with multiple redirect URIs.
services/​src/​main/​java/​org/​keycloak/​organization/​admin/​resource/​OrganizationInvitationResource.java Appends the resolved redirect URI to new-user registration links.

Review effort: Balanced

@Praiztl
Praiztl commented Nov 27, 2026
Copy link
Copy Markdown
Author

Thanks for the review, @vramik. Marked it ready. Happy to extend the test to complete registration with the multi-redirect client if you'd like that extra coverage, just let me know.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 12:06
@Praiztl
Praiztl commented Nov 27, 2026
Copy link
Copy Markdown
Author

The latest commit (07036ed) addresses Copilot's regression note. The resolved redirect URI is now validated with RedirectUtils.verifyRedirectUri before it is appended, so a client Home URL that is not a registered redirect URI is omitted and the existing single redirect URI fallback is kept. I added a regression test, testRegistrationLinkOmitsRedirectUriWhenClientBaseUrlIsNotARegisteredRedirectUri, for that case and confirmed the full OrganizationInvitationTokenTest class passes.

Copilot AI 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.

🟡 Changes recommended

Invitation redirect validation ignores the client option permitting OIDC response parameters, so invitations can still fail when multiple redirects are registered.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment on lines +240 to +242
if (client != null && RedirectUtils.verifyRedirectUri(session, invitationTarget.redirectUri, client) != null) {
builder.queryParam(OAuth2Constants.REDIRECT_URI, invitationTarget.redirectUri);
}
Copilot AI balanced review requested due to automatic review settings November 27, 2026 12:17
Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the change enabling invitation registration with clients that have multiple redirect URIs.

1 open issue

Review effort: Balanced

@Praiztl
Praiztl commented Nov 27, 2026
Copy link
Copy Markdown
Author

On the OIDC response parameter note: this is a deliberate scope decision. The 3-arg RedirectUtils.verifyRedirectUri uses the default forbidden-parameter set, which matches the registration endpoint's behaviour for the default configuration. The two only diverge when a client has the legacy isAllowOidcParamsInRedirectUris option enabled and its resolved redirect URI carries an OIDC response parameter, which is a narrow backward-compat case outside the multiple-redirect-URI scenario this issue targets. I would rather keep the fix minimal than replicate the full endpoint policy here, but I am happy to extend it if a maintainer prefers to close that gap too.

@stianst stianst added the kind/bug Categorizes a PR related to a bug label Nov 27, 2026
@vramik
vramik requested a review from pedroigor December 1, 2026 13:18
@Praiztl
Praiztl force-pushed the fix/55412-org-invite-redirect-uri branch from 533ebe7 to fc3a417 Compare December 3, 2026 09:07
Copilot AI balanced review requested due to automatic review settings December 3, 2026 09:07
8BD0 Copilot AI 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.

🟡 Changes recommended

Invitation redirect handling ignores OIDC-parameter compatibility settings and appends rewritten out-of-band URIs, causing previously valid registration flows to fail.

2 open issues

Review effort: Balanced

String validRedirectUri = client == null ? null
: RedirectUtils.verifyRedirectUri(session, invitationTarget.redirectUri, client);
if (validRedirectUri != null) {
builder.queryParam(OAuth2Constants.REDIRECT_URI, validRedirectUri);
@Praiztl
Praiztl force-pushed the fix/55412-org-invite-redirect-uri branch from fc3a417 to 08495bd Compare December 3, 2026 11:17
Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:17
Copilot AI 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.

🔵 Needs a closer look

Invitation redirect validation ignores the global/per-client compatibility setting, rejecting valid registered URLs and leaving clients with multiple redirect URIs with broken invitation links.

2 open issues

Review effort: Balanced

Closes keycloak#55412

Signed-off-by: Tochukwu Chikezie <95018735+Praiztl@users.noreply.github.com>
…on invite link

Signed-off-by: Tochukwu Chikezie <95018735+Praiztl@users.noreply.github.com>
Signed-off-by: Tochukwu Chikezie <95018735+Praiztl@users.noreply.github.com>
@Praiztl
Praiztl force-pushed the fix/55412-org-invite-redirect-uri branch from 08495bd to d913edc Compare December 4, 2026 09:58
Copilot AI balanced review requested due to automatic review settings December 4, 2026 09:58
Copilot AI 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.

🔵 Needs a closer look

Redirect validation still ignores allowed OIDC parameters and replaces registered out-of-band URIs with rejected callback URLs, breaking invitation registration for affected clients.

2 open issues

Review effort: Balanced

@Praiztl
Praiztl commented Dec 4, 2026
Copy link
Copy Markdown
Author

@vramik thanks for the review. Your approval is in, and the only thing left is the CI run, which is currently waiting on a maintainer to approve the workflow. Could you approve the run when you get a chance so this can merge? Happy to rebase or address anything else if needed.

@vramik
vramik commented Dec 4, 2026
Copy link
Copy Markdown
Contributor

@Praiztl thank you! As you pointed out, CI is waiting for a maintainer and I am not one of them, @pedroigor will trigger it once he gets to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes a PR related to a bug team/core-iam

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organization invite registration link fails when targeting a client with multiple redirect URIs

4 participants

0