Skip to content

Fail-closed guard for PAYLOAD-source authorization - #1494

Merged
openinx merged 2 commits into
unitycatalog:mainfrom
yili-db:auth-block-empty-body
Jul 24, 2026
Merged

openinx merged 2 commits into
unitycatalog:mainfrom
yili-db:auth-block-empty-body

Conversation

@yili-db

@yili-db yili-db commented Apr 17, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes
Fail-closed guard for PAYLOAD-source authorization

UnityAccessDecorator authorizes body-field (PAYLOAD) locators inside Armeria's peekData callback, which only fires for a request that delivers a complete JSON body. A body-less, non-JSON, or malformed request silently skips that authorization while the handler still runs. This is defense in depth: every current PAYLOAD endpoint also binds a required POJO body, so such requests already fail Jackson binding with a 400.

  • Add a per-request AUTH_PENDING attribute, set on entry to the PAYLOAD path and cleared only after the authorization evaluation runs.
  • Add AuthorizationGateConverter, which denies with 403 PERMISSION_DENIED at body-binding time if AUTH_PENDING is still set.
  • Wire the gate via gatedJackson() in UnityCatalogServer.

Follow-up: widening peekData's payload-recognition heuristic (charset-qualified content types, trailing whitespace) is deferred so the gate cannot deny valid non-SDK requests; current SDK clients are unaffected.

Tested: SdkCatalogAccessControlCRUDTest asserts a body-less POST /catalogs returns 403 before the handler runs.

@timothyw553 timothyw553 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. solution makes sense -- a skipped check turns into a request denied, right?

one thing that AI flagged was the "is this JSON?" check uses an exact match (equals(MediaType.JSON) see https://github.com/yili-db/unitycatalog/blob/78f138912cafdbd974869a092665dc1cac2ea80c/server/src/main/java/io/unitycatalog/server/auth/decorator/UnityAccessDecorator.java#L442), so a content-type like application/json; charset=utf-8 wouldn't match. in practice, if everyone goes through this SDK, which sends plain application/json, then it is fine.

but if they don't go through the sdk, instead, we should use Armeria's contentType.isJson()

@yili-db

yili-db commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

LGTM. solution makes sense -- a skipped check turns into a request denied, right?

one thing that AI flagged was the "is this JSON?" check uses an exact match (equals(MediaType.JSON) see https://github.com/yili-db/unitycatalog/blob/78f138912cafdbd974869a092665dc1cac2ea80c/server/src/main/java/io/unitycatalog/server/auth/decorator/UnityAccessDecorator.java#L442), so a content-type like application/json; charset=utf-8 wouldn't match. in practice, if everyone goes through this SDK, which sends plain application/json, then it is fine.

but if they don't go through the sdk, instead, we should use Armeria's contentType.isJson()

Yes it's a defense in depth to turn any skip of auth into an error. This is one baby step forward. I will have more PRs to handle other issue including the JSON type matching, JSON completeness guessing, etc.

Class<?> expectedResultType,
ParameterizedType expectedParameterizedResultType)
throws Exception {
if (Boolean.TRUE.equals(ctx.attr(UnityAccessDecorator.AUTH_PENDING))) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when will we set this UnityAccessDecorator.AUTH_PENDING attr in the context ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final RequestConverterFunction delegate;

public AuthorizationGateConverter(RequestConverterFunction delegate) {
this.delegate = Objects.requireNonNull(delegate, "delegate");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a more clear error message if it's null ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never meant to be null at all. It's just the production version of assert.
Removing this "delegate" string. The exception NullPointerException should be self explanatory.

* UnityAccessDecorator#AUTH_PENDING} on entry to the PAYLOAD path and clears it only after the
* authorization evaluation succeeds; if the flag is still {@code true} when a parameter is being
* bound, {@code peekData}'s callback never fired (no body, non-JSON content-type, malformed JSON,
* trailing whitespace) and the request must be denied.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the flag is still {@code true} when a parameter is being

  • bound, {@code peekData}'s callback never fired (no body, non-JSON content-type, malformed JSON,
  • trailing whitespace) and the request must be denied.

https://github.com/unitycatalog/unitycatalog/pull/1494/changes#diff-b9504c8a386aa1943559c357fa7ce1fcc952f4e0f45df99b89b17807213699faR42-R45
In that case, we actually are throwing the PERMISSION_DENIED exception, which actually swallow the real malformed detailed. will that make it even worst to the developer to understand the response ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the perfect error message throwing out.
The priority here is security: making sure it fails with PERMISSION_DENIED instead of going through.

In a follow up PR I will deal with this malformed/incomplete body problem and get rid of the processPeekData entirely.

yili-db added 2 commits July 22, 2026 16:01
UnityAccessDecorator reads body fields for authorization via Armeria's peekData callback, which only fires when a body chunk arrives AND the chunk parses as complete JSON. Body-less requests, non-JSON Content-Type, malformed JSON, and JSON with trailing whitespace all silently skip checkAuthorization while the handler still runs.

This is not a live vulnerability: every endpoint using a PAYLOAD locator today also requires a POJO body, so empty/malformed requests fail at Jackson binding (400) before the handler executes. The guard is defense in depth against a future endpoint where Jackson's accident doesn't hold.

Fix:
- New per-request AUTH_PENDING attribute, set true on entry to the PAYLOAD path and cleared only after checkAuthorization succeeds.
- New AuthorizationGateConverter wraps Jackson: if AUTH_PENDING is still true at body-binding time, deny with 403 PERMISSION_DENIED.
- UnityCatalogServer wires the gate via a gatedJackson() helper so every annotated service picks it up automatically.

Tested end-to-end: SdkCatalogAccessControlCRUDTest sends a body-less POST /catalogs and asserts the proper 403 response.

Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
@yili-db
yili-db force-pushed the auth-block-empty-body branch from 78f1389 to 67db88a Compare July 22, 2026 23:12
@yili-db
yili-db requested a review from openinx July 22, 2026 23:12

@openinx openinx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @yili-db .

@openinx
openinx merged commit ed504de into unitycatalog:main Jul 24, 2026
14 of 16 checks passed
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