Skip to content

Fixes #31346: answer 401 without echoing the token when a Basic/LDAP refresh token is expired - #35034

Merged
chirag-madlani merged 1 commit into
mainfrom
chirag-madlani/issue-31346-close
Oct 9, 2026
Merged

chirag-madlani merged 1 commit into
mainfrom
chirag-madlani/issue-31346-close

Conversation

@chirag-madlani

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #31346

With Basic or LDAP auth, an expired refresh token made /api/v1/auth/refresh (and /api/v1/users/refresh) answer 400 with the token UUID in the body ("Expired token. Please login again : <uuid>"). An empty token was a 400 too. Both are rejected credentials, so BasicAuthenticator and LdapAuthenticator now throw AuthenticationException with a fixed message. The servlet failure handler (SecurityUtil.writeFailureResponse) and the JAX-RS mapper (CatalogGenericExceptionMapper) already turn that exception into a 401, so both endpoints answer 401 and the token never reaches the response.

Earlier PRs fixed the other cases in the issue, and this PR doesn't change them:

The token UUID is no longer written to the server log either: a refresh token is a credential, and once it has expired it tells an operator nothing.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • Basic auth: log in, expire the stored refresh token, call /api/v1/auth/refresh → 401, and the body doesn't contain the token (the issue's own repro).

Unit tests

  • No new unit test: the exception-to-401 mapping is already covered in SecurityUtilTest, and the behavior is covered end to end by the IT below.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added/updated: SessionMultiNodeIT#expiredRefreshTokenIsRejectedWithoutEchoingIt (MySQL and Postgres SQL)

The run below was taken with this diff uncommitted on 9f52d6702fa2; the committed content is identical. The one failure, DomainIsolationIT#test_lineage_restrictedBotSeesOnlyOwnDomainNodes (Awaitility timed out after 1 minute waiting for the search index), passed when re-run alone with the same command. It's a lineage/domain-isolation test that doesn't touch refresh tokens, so I'm treating it as a flake (1 failure in 1 full run).

Local Java test run: FAILED

  • Commit: 9f52d6702fa2 (base origin/main) — uncommitted changes were present
  • Finished: 2026-10-09 13:12 UTC · 66.6 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-mcp (1 class), openmetadata-service (6 classes) 7 127 0 0 2.4 passed
integration mysql-elasticsearch · parallel 35 1860 1 158 16.9 FAILED
integration mysql-elasticsearch · isolated 2 18 0 0 9.9 passed
integration mysql-elasticsearch · rdf 1 9 0 0 29.3 passed
integration cache-tests · isolated 2 11 0 0 8.1 passed

Failed: DomainIsolationIT#test_lineage_restrictedBotSeesOnlyOwnDomainNodes(TestNamespace)

Tests run locally

  • unit · openmetadata-mcp (1 class), openmetadata-service (6 classes): BasicAuthLoginServletTest (5 passed), BasicAuthServletHandlerTest (2 passed), LdapAuthServletHandlerTest (5 passed), LdapAuthenticatorTest (5 passed), LdapLookupConnectionPoolTest (3 passed), SecurityUtilTest (100 passed), TestLoginCredentialHandlerTest (7 passed)
  • integration · mysql-elasticsearch · parallel: 35 classes, 1702 tests executed (listed below)
  • integration · mysql-elasticsearch · isolated: SessionMultiNodeIT (11 passed), UserMetricsResourceIT (7 passed)
  • integration · mysql-elasticsearch · rdf: RdfFusekiAuthorizationIT (9 passed)
  • integration · cache-tests · isolated: SessionRedisMultiNodeIT (8 passed), TokenRevocationRedisMultiNodeIT (3 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The step totals above are Maven's own counts.

integration · mysql-elasticsearch · parallel: 36 classes

AIGovernancePolicyResourceIT (4 passed), AppOperationPermissionsIT (10 passed), BaseEntityIT$ListEntityHistoryByTimestampPaginationTest (33 passed, 3 skipped), BotImpersonationIT (1 passed), BotResourceIT (31 passed, 4 skipped), BulkOperationPermissionsIT (1 passed), ConfigResourceIT (12 passed), DataContractPermissionIT (11 passed, 5 skipped), DatabaseSmokeIT (1 passed), DomainIsolationIT (83 passed, 6 skipped), EmailFirstIdentityIT (5 passed, 1 skipped), FeedAccessAuthzIT (16 passed, 1 skipped), GlossaryTermRelationSettingsPermissionsIT (12 passed), GlossaryTermResourceIT (102 passed, 2 skipped), McpOAuthIT (19 passed), McpPermissionIT (2 passed), OAuth2TokenManagerIT (8 passed), PermissionsResourceIT (43 passed, 4 skipped), PipelineStatusAuthorizationIT (6 passed), PolicyResourceIT (223 passed, 35 skipped), QueryVisibilityPolicyIT (86 passed, 1 failed, 6 skipped), RoleResourceIT (185 passed, 32 skipped), SamlSecurityConfigIT (9 passed), SecurityServiceResourceIT (53 passed, 1 skipped), SeedDataPresenceIT (4 passed), ServiceAttributePolicyIT (91 passed, 7 skipped), TableResourceIT (164 passed, 6 skipped), TaskPermissionsIT (15 passed, 1 skipped), TestCaseCsvDomainIsolationIT (70 passed, 5 skipped), TestLoginSessionSweepIT (5 passed, 1 skipped), UserDefaultTeamAssignmentIT (1 passed), UserImportPrivilegeEscalationIT (53 passed, 5 skipped), UserPreferencesIT (6 passed, 1 skipped), UserResourceIT (188 passed, 21 skipped), UserTeamAssignmentPrivilegeIT (87 passed, 10 skipped), WorkflowTriggerPermissionsIT (15 passed)

Why these tests
  • area security ← openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java, openmetadata-service/src/main/java/org/openmetadata/service/security/auth/LdapAuthenticator.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/SessionMultiNodeIT.java
  • smoke ← code other than a test class changed
Impacted, not run locally (2)
  • GoogleSsoSignInUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
  • GoogleSsoBootstrapUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
Commands
mvn -B package -pl openmetadata-mcp,openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=BasicAuthLoginServletTest,BasicAuthServletHandlerTest,LdapAuthServletHandlerTest,LdapAuthenticatorTest,LdapLookupConnectionPoolTest,SecurityUtilTest,TestLoginCredentialHandlerTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<35 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=SessionMultiNodeIT,UserMetricsResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf -Dit.test=RdfFusekiAuthorizationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=global-state -Dit.test=SessionRedisMultiNodeIT,TokenRevocationRedisMultiNodeIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Covered by the IT above, which reproduces the issue's steps against a live server.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For UI changes: I attached a screen recording and/or screenshots above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Decision check: no durable decision; this aligns Basic/LDAP with the existing 401 contract for rejected credentials.
  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

…refresh token is expired

An expired refresh token threw CustomExceptionMessage(BAD_REQUEST) with the
token UUID in its message, which /auth/refresh wrote to the client as a 400.
An empty token was a 400 too. Both are rejected credentials: throw
AuthenticationException with a fixed message so the servlet path and the
/users/refresh resource answer 401 and the token never reaches the wire.
@chirag-madlani
chirag-madlani requested a review from a team as a code owner October 9, 2026 13:20
Copilot AI balanced review requested due to automatic review settings October 9, 2026 13:20

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Changing Basic/LDAP refresh failures from 400 to 401 could alter client reauthentication handling; expired credentials stay rejected and token UUIDs are no longer exposed.

Basic and LDAP authenticators now throw AuthenticationException with a fixed message for expired or empty refresh tokens, so /api/v1/auth/refresh and /api/v1/users/refresh return 401 without echoing the token. The token UUID is also no longer written to the server log. No issues found during review.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

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

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

✅ SSO Login Nightly — PASSED

View workflow run · Commit 8c7fe5b

Provider Status Pass Fail Flaky Skip Duration
basic ✅ pass 28 0 0 0 7m 04s
ldap ✅ pass 7 0 0 0 1m 06s
keycloak-oidc-confidential ✅ pass 12 0 0 0 1m 32s
keycloak-oidc-public ✅ pass 11 0 0 0 1m 39s
msal-mock ✅ pass 7 0 0 0 0m 56s
auth0-mock ✅ pass 6 0 0 0 1m 03s
okta ⏩ skipped - - - - -
keycloak-azure-saml ✅ pass 23 0 0 0 6m 51s
keycloak-azure-saml-crosssite ⏩ skipped - - - - -

Totals: 94 passed · 0 failed · 0 flaky · 0 skipped · duration 20m 16s

@chirag-madlani
chirag-madlani added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit 2444b4a Oct 9, 2026
84 checks passed
@chirag-madlani
chirag-madlani deleted the chirag-madlani/issue-31346-close branch October 9, 2026 20:23

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 UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth: answer 401 with a sanitized message when /auth/refresh rejects an expired or rotated refresh credential

3 participants