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

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

8000
@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
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
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

Closes keycloak#51440

Signed-off-by: Shubham <87247136+shuseng8@users.noreply.github.com>
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
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!

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

3 participants

0