8000 Reject attribute-condition configuration that resolves to no entry or several by antoniocasagrande-airia · Pull Request #53081 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Reject attribute-condition configuration that resolves to no entry or several - #53081

Open
antoniocasagrande-airia wants to merge 2 commits into
keycloak:mainfrom
antoniocasagrande-airia:workflow-attribute-condition-config-validation
Open

antoniocasagrande-airia wants to merge 2 commits into
keycloak:mainfrom
antoniocasagrande-airia:workflow-attribute-condition-config-validation

Conversation

@antoniocasagrande-airia
@antoniocasagrande-airia antoniocasagrande-airia commented Sep 22, 2026 •
Copy link
Copy Markdown

UserAttributeWorkflowConditionProvider.parseKeyValuePair loads a condition's configuration through Properties, which is the format the documentation specifies. Two shapes get past it, and both leave a condition matching a resource set that was never configured.

No entry at all — the input is empty, or its key is one Properties reads as a # or ! comment. stringPropertyNames().iterator().next() then raises a bare NoSuchElementException rather than the WorkflowInvalidStateException the method already throws a few lines earlier.

More than one entry, from multi-line input. Properties is a Hashtable, so the iterator resolves to an arbitrary entry and a stray newline silently selects a different attribute than the intended one. A key repeated on a second line is the same problem in another form: Properties keeps one entry per key and the last value wins, so entries are counted as they load rather than read back with size().

This requires exactly one entry. No valid configuration changes meaning: presence-only keys, both documented separators, comma-separated values and escaped separators all parse as before — only input that previously crashed or resolved arbitrarily is now rejected. That also completes the "a single param for each condition" invariant #43716 set out to establish.

Fixed in the shared helper rather than in one condition, so has-user-attribute and the client-attribute condition being added in #52189 keep identical configuration semantics.

Testing

New unit test in model/jpa. It pins the accepted grammar (both documented separators, presence-only keys, comma-separated values, escaped separators) as well as the two rejections, so the fix cannot narrow what already works.

Verified locally: mvn -pl model/jpa -am test -Dtest=UserAttributeWorkflowConditionProviderTest passes 8/8, and mvn spotless:check -pl model/jpa is clean. I also confirmed the tests fail without the fix — reverting the guard reproduces the NoSuchElementException on the no-entry cases and silently accepts the multi-line ones, and counting with size() instead fails only the repeated-key case.

Context: this was originally part of #51629, which I have closed; the condition work there is superseded by #52189. This half is an independent fix to shipped code, so it is on its own.

Copilot AI balanced review requested due to automatic review settings September 22, 2026 17:04
@antoniocasagrande-airia
antoniocasagrande-airia requested a review from a team as a code owner September 22, 2026 17:04
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.

Copilot review overview

🟡 Changes recommended

Duplicate-key multiline input still bypasses the new guard.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Hardens workflow attribute-condition parsing to reject invalid property cardinality.

Changes:

  • Requires one parsed property.
  • Adds parsing and rejection tests.
File Description
UserAttributeWorkflowConditionProvider.java Adds cardinality validation.
UserAttributeWorkflowConditionProviderTest.java Covers accepted and rejected inputs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

… several

parseKeyValuePair loads the configuration through Properties, which is the format
the documentation specifies, but two shapes get past it and both make a condition
match a resource set that was never configured:

- No entry at all, when the input is empty or its key is one Properties reads as
  a '#' or '!' comment. stringPropertyNames().iterator().next() then raises a
  bare NoSuchElementException rather than the WorkflowInvalidStateException the
  method already throws a few lines earlier.
- More than one entry, from multi-line input. Properties is a Hashtable, so the
  iterator picks an arbitrary entry and a stray newline silently selects a
  different attribute than the intended one.

Require exactly one entry. No valid configuration changes meaning: both
documented separators, presence-only keys, comma-separated values and escaped
separators all parse as before, and only input that previously crashed or
resolved arbitrarily is now rejected.

Fixed in the shared helper rather than in one condition, so has-user-attribute
and has-client-attribute keep identical configuration semantics.

Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Properties keeps one entry per key, so "plan=gold\nplan=silver" left size() at one and
the guard accepted it, resolving silently to the last value. Count entries as they load
instead, and pin the repeated-key case in the test.

Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 18:02
@antoniocasagrande-airia
antoniocasagrande-airia force-pushed the workflow-attribute-condition-config-validation branch from bc42ad0 to 17859a9 Compare October 14, 2026 18:02
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

The focused fix covers both failure modes, including duplicate keys, with regression tests and no unresolved issues.

1 open finding

🧠 Review effort: Balanced

@sguilhen
sguilhen commented Dec 2, 2026
Copy link
Copy Markdown
Contributor

@antoniocasagrande-airia I want to pick this up - sorry for the delay, its been really busy these past couple of months. I've opened #55757 to track this as we require the PRs to have an issue they close.

Can you rebase than edit your commit and PR description to include "Closes #55757"?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0