Skip to content

AuthZEN: accept action.properties and ignore unknown request fields - #55264

Open
Inf1mum wants to merge 1 commit into
keycloak:mainfrom
Inf1mum:keycloak-54542-authzen-lenient-parsing
Open

Inf1mum wants to merge 1 commit into
keycloak:mainfrom
Inf1mum:keycloak-54542-authzen-lenient-parsing

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #54542

What

AuthZEN evaluation requests that carry action.properties, unknown keys inside options, or any unknown field (top-level or inside subject, resource, action, or an evaluations item) are currently rejected with 400 Bad Request before authentication. Two causes, both fixed here:

  1. AuthZen.Action was declared as record Action(String name), so the OPTIONAL properties key defined by AuthZEN 1.0 Section 5.3 failed request parsing with Unrecognized field "properties".
  2. The AuthZEN request records did not opt out of the server-wide strict Jackson behaviour, so any unknown field failed parsing and KcUnrecognizedPropertyExceptionHandler turned it into a 400. AuthZEN 1.0 Section 10.1.1 requires: "To ensure forward compatibility, receivers MUST ignore unknown fields present in request or response bodies."

How

  • Added the optional properties map to AuthZen.Action (a convenience Action(String name) constructor keeps existing call sites working).
  • Annotated the AuthZEN request records (Subject, Resource, Action, EvaluationRequest, EvaluationItem, Options, EvaluationsRequest) with @JsonIgnoreProperties(ignoreUnknown = true).

Scope note (regarding the open question in the issue): action.properties is accepted but, in this first step, not merged into the evaluation context, as proposed in the issue description. If maintainers prefer it to feed the claim/context map, that can be a follow-up together with the related property-collision questions discussed in #53328 and #54848.

Tests

  • AuthZenEvaluationTest: action.properties accepted; unknown fields ignored inside action, subject, resource, and at the top level (all previously 400).
  • AuthZenEvaluationsTest: unknown keys inside options next to evaluations_semantic; action.properties plus an unknown field inside an evaluations item.

The pre-existing 400 behaviour for missing/invalid required fields and invalid JSON is unchanged and remains covered by the tests already in these classes.

AuthZEN 1.0 Section 5.3 defines an optional properties key on the action
object, and Section 10.1.1 requires receivers to ignore unknown fields in
request bodies. The AuthZEN request records inherited the server-wide
strict Jackson behaviour, so requests carrying action.properties, unknown
keys inside options, or any unknown field were rejected with 400 before
authentication.

- add the optional properties map to AuthZen.Action
- annotate the AuthZEN request records with @JsonIgnoreProperties(ignoreUnknown = true)
- per the open question in the issue, action.properties is accepted but
  not merged into the evaluation context in this first step
- cover action.properties, unknown fields (top-level, subject, resource,
  action, evaluations item) and unknown option keys with integration tests

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
@Inf1mum
Inf1mum requested a review from a team as a code owner November 17, 2026 11:09
Copilot AI balanced review requested due to automatic review settings November 17, 2026 11:09

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 action name is not required, so invalid requests can return a 200 denial instead of a 400 error.

1 open issue
What changed in this PR

Improves AuthZEN 1.0 request compatibility in Keycloak’s authorization services, addressing #54542.

Changes:

  • Accepts optional action.properties without adding them to the policy evaluation context.
  • Ignores unknown fields across single and batch evaluation request records.
  • Adds regression tests for action properties and unknown request fields.
File Description
authzen/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​authzen/​AuthZenEvaluationTest.java Tests action properties and unknown fields in single evaluations.
authzen/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​authzen/​AuthZenEvaluationsTest.java Tests unknown option keys and action properties within batch items.
authzen/​services/​src/​main/​java/​org/​keycloak/​authorization/​authzen/​AuthZen.java Adds action properties, preserves the convenience constructor, and enables unknown-field tolerance.

Review effort: Balanced

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record Action(String name) {}
public record Action(String name, Map<String, Object> properties) {

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

I tested the PR locally: I replaced the AuthZEN services jar in today's quay.io/keycloak/keycloak:nightly image (999.0.0-SNAPSHOT, built 2026-11-17) with one built from this branch and compared it with the unmodified image. I also ran the authzen/tests/base suite (123/123, Spotless clean).

All cases from the issue now return 200 with the expected decision, where nightly returns 400:

  • action.properties (scalar, nested, empty, null)
  • unknown fields at the top level and inside subject, resource and action
  • unknown fields inside an evaluations item, at the top level of an Access Evaluations request, and unknown keys inside options (also when evaluations_semantic is absent)

action.properties does not reach the evaluation context. A regex policy on channel with "action":{"name":"read","properties":{"channel":"web"}} still denies, as the description says.

The existing 400s are unchanged: missing required fields, invalid JSON, an unknown subject.type, an invalid evaluations_semantic, and a non-object action.properties (string or array).

Two side effects that may be worth noting in the description:

  • The body is parsed before the token is checked, so a request with an unknown field and a missing or invalid token used to get 400. It now gets 401.
  • A duplicate key in action, for example "action":{"name":"write","name":"read"}, returns 500 on nightly (InvalidDefinitionException: No fallback setter/field defined for creator property 'name'). With this PR the last value wins, which matches what already happens for a duplicate key in subject.

The PR also merges cleanly with #55258, and the combined suite passes (126/126).

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.

AuthZEN: requests with action.properties or unknown fields are rejected with 400

3 participants