Skip to content

fix(auth): clear request state outside jersey - #36173

Merged
Vishnuujain merged 2 commits into
mainfrom
fix/bot-token-fresh-read
Oct 26, 2026
Merged

Vishnuujain merged 2 commits into
mainfrom
fix/bot-token-fresh-read

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Part of a larger set of MCP and auth fixes.

  • Servlets and filters outside Jersey (MCP transport, WebSocket handshake, SSO callbacks) run on the same Jetty threads as REST but never cleared the per-request entity cache and contexts, so an entity one request cached could be returned to a later request on that thread.
  • New PerRequestContextCleanupFilter on /* clears that state before and after every request on the application context. The bot and personal access token loaders also read the user inside FreshReadScope, which covers threads the filter does not wrap.
  • Decision record: ADR:2026-10-23-every-jetty-request-clears-per-request-thread-state.

Type of change:

  • Bug fix

Tests:

Unit tests

  • PerRequestContextCleanupFilterTest (3), BotTokenCacheTest (1) and UserTokenCacheTest (1); each fails with its change reverted.
  • PerRequestContextCleanerTest, RequestEntityCacheTest, CredentialTokenStateTest, SocketAddressFilterTest also pass.

Backend integration tests

Not run locally (touching OpenMetadataApplication selects the full suite); the merge queue runs them.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    Reviewed 378322e. No 🔴. 🟡 UserTokenCache had no test: added UserTokenCacheTest in 9600884. 🟡 nothing tests the filter's registration order: the decision record names the reviewer as its guard; an IT needs a new accessor on the test bootstrap, left for a follow-up.
  • Decision check: added ADR:2026-10-23-every-jetty-request-clears-per-request-thread-state.
  • I have added a test that covers the exact scenario we are fixing.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects were found.

Summary

Adds cleanup before and after application requests, including handlers outside Jersey.

  • Application requests start and end with clean per-request thread state.
  • Bot and personal-token reloads read users in a fresh scope.

No actionable issues were found. Tests were inspected, not run.

Vishnuujain explicitly deferred a registration-order integration test because the test bootstrap needs a new accessor.

Diagram

sequenceDiagram
  participant Jetty
  participant Cleanup as PerRequestContextCleanupFilter
  participant Handler as Application handler
  participant Loader as Token loader
  Jetty->>Cleanup: Request
  Cleanup->>Cleanup: Clear request state
  Cleanup->>Handler: Continue request
  opt Load tokens
    Handler->>Loader: Read current tokens
    Loader->>Loader: Enter FreshReadScope
    Loader->>Loader: Read user with an empty request cache
    Loader->>Loader: Close scope
    Loader-->>Handler: Tokens
  end
  Handler-->>Cleanup: Return or throw
  Cleanup->>Cleanup: Clear request state in finally
Loading

Reviews (1) · Last reviewed commit: "user token cache test" · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 25, 2026
@gitar-bot

gitar-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Request-wide context cleanup and fresh token-user reads change authentication decisions; incorrect scoping could reuse stale credentials or reject valid tokens.

Adds PerRequestContextCleanupFilter on /* to clear per-request entity cache and context before and after every Jetty request, and wraps bot and personal access token loaders in FreshReadScope, preventing cached entities from leaking across requests on the same thread. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown
Contributor

✅ SSO Login Nightly — PASSED

View workflow run · Commit 2e527cb

Provider Status Pass Fail Flaky Skip Duration
basic ✅ pass 28 0 0 0 5m 57s
ldap ✅ pass 7 0 0 0 0m 47s
keycloak-oidc-confidential ✅ pass 12 0 0 0 1m 33s
keycloak-oidc-public ✅ pass 11 0 0 0 1m 14s
msal-mock ✅ pass 7 0 0 0 0m 50s
auth0-mock ✅ pass 6 0 0 0 0m 55s
okta ⏩ skipped - - - - -
keycloak-azure-saml ✅ pass 23 0 0 0 5m 55s
keycloak-azure-saml-crosssite ⏩ skipped - - - - -

Totals: 94 passed · 0 failed · 0 flaky · 0 skipped · duration 17m 15s

@Vishnuujain Vishnuujain self-assigned this Oct 25, 2026
@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit b6b4778 Oct 26, 2026
92 of 94 checks passed
@Vishnuujain
Vishnuujain deleted the fix/bot-token-fresh-read branch October 26, 2026 08:00

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants