8000 Reject empty credential labels in the Account API and setup flows by shuseng8 · Pull Request #54849 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Reject empty credential labels in the Account API and setup flows - #54849

Open
shuseng8 wants to merge 1 commit into
keycloak:mainfrom
shuseng8:issue-51440
Open

shuseng8 wants to merge 1 commit into
keycloak:mainfrom
shuseng8:issue-51440

Conversation

@shuseng8
@shuseng8 shuseng8 commented Nov 8, 2026 •
Copy link
Copy Markdown
Contributor

Closes #51440

This reworks #54849 after the team discussion in #54849 (comment).

Instead of allowing empty credential labels in the Admin API, empty or blank labels are now rejected in the Account REST API and in the OTP and Passkey setup flows. The Admin API already rejected empty labels and is unchanged.

Changes:

  • Account REST API PUT /credentials/{id}/label returns 400 missingCredentialLabel for null, empty, or whitespace-only labels.
  • The Configure OTP required action always requires a device name, including for the first OTP device. The login form always shows the required marker.
  • WebAuthn/Passkey registration re-prompts in the browser when the label is blank. Cancel still falls back to the default label. The server rejects a blank label before the registration challenge is consumed. Passwordless registration inherits this check.
  • Tests updated so first-OTP setup supplies a device name. New Account API coverage for empty, blank, and valid labels.
  • Section added at the end of Notable changes in changes-27_0_0.adoc.

AI assistance: An AI agent was used to help implement this change from a written plan. I reviewed the code and tests and take responsibility for the contribution.

@shuseng8
shuseng8 requested a review from a team as a code owner November 8, 2026 19:21
Copilot AI balanced review requested due to automatic review settings November 8, 2026 19:21
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 aligning Admin API credential-label clearing with the Account API.

No open issues 🎉

What changed in this PR

Aligns the Admin API with the Account API’s acceptance of empty credential labels, addressing #51440 while preserving duplicate-label validation for named credentials.

Changes:

  • Treats empty or blank Admin API labels as requests to clear the label, storing null.
  • Replaces the rejection test with coverage that clears two OTP credential labels without a duplicate-label conflict.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​user/​UserCredentialTest.java Verifies empty and whitespace-only labels clear two OTP credential labels to null.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​admin/​UserResource.java Normalizes empty or blank labels to null and documents the clearing behavior.

Review effort: Balanced

@vaceksimon vaceksimon self-assigned this Nov 9, 2026
@vaceksimon vaceksimon 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.

lgtm

Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:52
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 aligning Admin API credential-label clearing with the Account API.

No open issues 🎉

Review effort: Balanced

@shuseng8
shuseng8 commented Nov 9, 2026
Copy link
Copy Markdown
Contributor Author

thanks @vaceksimon for your review, looking forward to get it merged. I see at the moment merging shows blocked as it requires a code owners review.

@vaceksimon
Copy link
Copy Markdown
Contributor

@shuseng8, we have discussed this within the team and decided that the second option is more optimal: reject empty credential labels in the user API. Sorry for the trouble. Would you still be up for providing a fix? Here is my suggestion:

The validation should be included in AccountCredentialResource, but not only there, because of #53544.

The credential label is also set during credential setup as a required action in LoginActionsService, so each credential type handles it separately.

OTP:

Passkeys:

@shuseng8 wdyt?
cc @keycloak/core-authn

@shuseng8
Copy link
Copy Markdown
Contributor Author

Hi @vaceksimon, no trouble at all, and thanks for coming back after the team discussion. I'm happy to take on the new approach and reject empty credential labels in the Account API and the setup flows.

My plan:

  • Add an empty/blank label check in AccountCredentialResource, returning 400 with the same missingCredentialLabel error the Admin API already uses.
  • In UpdateTotp, drop the existing-credential count check so a device name is always required, including for the first OTP.
  • In webauthnRegister.js, re-prompt if the label is empty (Cancel still falls back to the default label, as today), and add a matching server-side check in WebAuthnRegister.
  • Revert this PR's Admin API changes so the Admin API keeps rejecting empty labels.

Would you prefer that I rework this PR (rebase, update the title and description) or open a fresh one?

@vaceksimon
Copy link
Copy Markdown
Contributor

@shuseng8 I agree with the plan; you can carry on in this PR.

One thing I forgot: add a section about this to changes-27_0_0.adoc at the end of Notable changes.

@shuseng8
shuseng8 requested review from a team as code owners November 11, 2026 18:06
Copilot AI balanced review requested due to automatic review settings November 11, 2026 18:06
@shuseng8 shuseng8 changed the title Allow empty credential label in Admin API Reject empty credential labels in the Account API and setup flows Nov 11, 2026
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 mandatory device-name field is not announced as required to screen readers, and a duplicate credential label makes the recovery-code test pass without verifying successful setup.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 18:39
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 new server-side WebAuthn label rejection lacks regression coverage for missing, empty, and whitespace-only labels in regular and passwordless registration, including the expected error, no credential storage, and challenge reuse after correction.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:21
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 remain for the credential-label validation changes.

1 open issue

Review effort: Balanced

@shuseng8
Copy link
Copy Markdown
Contributor Author

Hi @vaceksimon, thanks for the review and suggestions! The changes have been addressed as per your plan. Empty/blank labels are now rejected in the Account API, the OTP setup (count check dropped) and Passkey registration (re-prompt + server-side check), and the note is added at the end of Notable changes in changes-27_0_0.adoc. I also addressed Copilot's suggestions (an accessibility fix plus WebAuthn regression tests for missing/blank labels). Could you please approve the CI workflow runs and review it further when you get a chance? Thanks!

Copilot AI balanced review requested due to automatic review settings November 14, 2026 06:24
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

There are no active review issues with the credential-label validation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shuseng8
10BC8 Copy link
Copy Markdown
Contributor Author

Hi @vaceksimon, I've rebased this onto the latest main and resolved the merge conflicts. Keycloak moved the login pages to PatternFly 6, so I updated the TOTP template to use the new field helper with the label always required, and kept the upgrade note last under Notable changes. The full build passes, and so do all the affected tests (new framework, WebAuthn, TOTP, broker and LDAP). Whenever you or another maintainer has time, a review and approval for the CI runs would be much appreciated. Thank you!

@shuseng8
Copy link
Copy Markdown
Contributor Author

Hi @ahus1, @vaceksimon approved this earlier. Since then I've addressed the remaining review feedback and rebased it onto the latest main, and there are no conflicts. Could you take a look and merge it if it looks good to you? The workflow runs also need a maintainer's approval before CI can start. Thanks!

@ahus1 ahus1 assigned ahus1 and vaceksimon and unassigned vaceksimon and ahus1 Nov 17, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 05:31
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 credential-label validation changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 11:19

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 block the credential-label validation changes.

No open issues 🎉

Review effort: Balanced

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

Hey @shuseng8, sorry for taking this long. I've reviewed the PR and it looks good to me.

Can I get another opinion from @rmartinc or @mabartos so we can trigger the CI?

@shuseng8
Copy link
Copy Markdown
Contributor Author

Np, @vaceksimon :) please let me know, if this changes in PR looks good and is eligible to merge 🚀 post the opinion from @rmartinc or @mabartos

Closes keycloak#51440

Signed-off-by: Shubham <87247136+shuseng8@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 09:12
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 upgrade note omits the new blank-label WebAuthn registration audit-event value and when it is emitted, leaving event consumers without needed migration guidance.

1 open issue

Review effort: Balanced

Empty or blank credential labels are now rejected in the Account REST API and in the OTP and Passkey setup flows.
The first OTP device, like every later device, requires a device name.
Clients that previously omitted a label when creating or renaming a credential must supply a non-empty value.
The Admin REST API already rejected empty labels and is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistency in credential label validation between Admin API and Account API

4 participants

0