Skip to content

fix(mcp): stop logging rejected MCP logins as exceptions - #33604

Merged
ShaileshParmar11 merged 1 commit into
mainfrom
suppress-invalid-creds-logging
Sep 19, 2026
Merged

ShaileshParmar11 merged 1 commit into
mainfrom
suppress-invalid-creds-logging

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

No linked issue — this came from a production stack trace rather than a filed report. The closest
issue, #32652, covers the same endpoint but was already closed by #32720; the unknown-account 500
below is a distinct bug that fix did not reach.

A rejected credential is the expected outcome of POST /mcp/login, not a fault, but the servlet
logged two of them with a full stack trace:

  1. Lockout. checkIfLoginBlocked's AuthenticationException was logged as
    LOG.warn("Login blocked for user", e) — a stack dump every time the lockout policy did exactly
    what it was configured to do.

  2. Unknown account. This one never reaches the AuthenticationException catch at all. Both
    authenticators report a non-existent account as CustomExceptionMessage
    (BasicAuthenticator.lookUserInProvider:553, LdapAuthenticator.lookUserInProvider:318), not as
    AuthenticationException, so it fell through to the generic handler: LOG.error(..., e) with a
    stack trace, and HTTP 500 instead of the login form. A typo'd username produced a server
    error page.

Both are now logged as events, and the unknown-account case gets the same inline
"Invalid username or password" form the wrong-password case already got.

The reported trace itself (wrong password for an existing user) was already fixed on main by
#32720, which corrected the servlet's import from service.exception.AuthenticationException to
service.security.AuthenticationException. This PR closes the two remaining paths in the same
method.

Type of change:

  • Bug fix

High-level design:

Small fix, but one decision is worth recording: how to tell a rejected credential apart from a real
fault, given both arrive as CustomExceptionMessage.

LDAP reuses that same type for an unreachable directory (LDAP_CONNECTION_ERROR), which must keep
reaching the generic handler and being logged in full. Status code can't discriminate — LDAP reports
an unknown user as 500 and a connection failure as 503, while Basic reports an unknown user
as 400. The only stable discriminator is errorType (INVALID_USER_OR_PASSWORD), which
WebServiceException held in a private field with no accessor. So:

  • WebServiceException — added getErrorType(). Purely additive; the nested ErrorMessage already
    exposed the same value.
  • BasicAuthLoginServlet — the new catch (CustomExceptionMessage) rethrows anything that isn't
    INVALID_USER_OR_PASSWORD, so infrastructure failures are unaffected.

Alternative rejected: matching on the exception message text. Brittle, and there are two different
strings (INVALID_USERNAME_PASSWORD, INVALID_EMAIL_PASSWORD) for the same condition.

No migration, schema, or API-contract impact. Behaviour change is confined to /mcp/login: an
unknown account now returns 200 + login form instead of 500.

Tests:

Use cases covered

  • Unknown username/email at the MCP login form → form re-renders inline with "Invalid username or
    password"; no 500, no stack trace in the log.
  • Wrong password for an existing account → unchanged behaviour, now logged without a stack trace.
  • Locked-out account → unchanged behaviour, now logged without a stack trace.
  • LDAP directory unreachable → still reaches the generic handler, still logged in full, still 500.

Unit tests

  • Added unit tests for the changed logic.
  • File updated: openmetadata-mcp/src/test/java/org/openmetadata/mcp/server/auth/handlers/BasicAuthLoginServletTest.java
    • doPost_unknownAccount_rendersLoginFormWithInvalidCredentialsMessage (new)
    • doPost_ldapDirectoryUnavailable_fallsThroughToGenericFailure (new — guards against the catch
      over-reaching and swallowing real faults)
  • Red/green verified: doPost_unknownAccount_... fails on the unpatched servlet (hits the 500
    path, BasicAuthLoginServletTest:221) and passes with the fix.
mvn -o -pl openmetadata-mcp -Dtest=BasicAuthLoginServletTest test
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 -- BasicAuthLoginServletTest
BUILD SUCCESS

Coverage (JaCoCo, static-code-analysis profile): every line added by this PR is covered,
including both branches of the new INVALID_USER_OR_PASSWORD check (2/2) and the rethrow. Class
line coverage is 47.9% (68/142) — the uncovered remainder is the pre-existing doGet,
auth-code-issue and redirect happy path, which this PR does not touch. The two missed lines inside
the changed region (250–251) are the pre-existing inner catch (Exception recordEx) block.

Full openmetadata-mcp module run: 674 tests, 0 failures, 10 errors — all 10 are
IdTokenValidatorTest, an okhttp/mockwebserver classpath mismatch
(NoSuchMethodError: okhttp3.internal.concurrent.TaskRunner.<init>). Confirmed pre-existing:
identical 10 errors on a clean origin/main checkout.

Backend integration tests

  • Not applicable — no REST API endpoint changes. /mcp/login is a browser-facing servlet in the
    MCP OAuth flow, covered by the unit tests above.

Ingestion integration tests

  • Not applicable — no ingestion changes.

Playwright (UI) tests

  • Not applicable — no UI changes.

Manual testing performed

Not performed — no local stack was started for this change. Verification was automated: the red/green
check above proves the unknown-account path changed from 500 to the inline form, and the
LDAP-unavailable test proves the new catch doesn't swallow real faults.

UI screen recording / screenshots:

Not applicable — no UI changes.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation> — N/A, no linked issue (see above).
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above — N/A, see above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: N/A — no schema changes.
  • For UI changes: N/A — no UI changes.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

Known adjacent issue, deliberately left out of scope

For a wrong password the failed attempt is counted twice — BasicAuthenticator.validatePassword
records it before throwing, and the servlet's catch records it again — which effectively halves
maxLoginFailAttempts on this endpoint. Pre-existing, unrelated to the logging fix, and changing it
alters lockout semantics, so it's better as its own PR.

🤖 Generated with Claude Code

RetriggerConfidence Score: 4/5

The PR is not yet safe to merge because an LDAP identity-attribute configuration failure is incorrectly converted into an invalid-credentials response.

Findings

  1. P1 LDAP Misconfiguration Is Masked ▶
Summary

This PR changes MCP browser-login error handling so expected credential rejections no longer produce exception stack traces and unknown accounts return the inline login form rather than HTTP 500.

  • Adds an accessor for WebServiceException.errorType.
  • Handles INVALID_USER_OR_PASSWORD exceptions as rejected credentials.
  • Removes the lockout exception stack trace.
  • Adds coverage for unknown accounts and unavailable LDAP directories.
  • The classification currently also masks an LDAP identity-attribute configuration failure that reuses the same error type.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[POST /mcp/login] --> B[Resolve account and validate password]
  B -->|AuthenticationException| C[Render invalid-credentials form]
  B -->|CustomExceptionMessage| D{errorType is INVALID_USER_OR_PASSWORD?}
  D -->|No| E[Generic error handler and HTTP 500]
  D -->|Yes: unknown account or bad LDAP credentials| C
  D -->|Yes: LDAP attribute misconfiguration| F[Incorrectly render invalid-credentials form]
Loading

Reviews (1) · Last reviewed commit: "fix(mcp): stop logging rejected MCP logi..."

A rejected credential is the expected outcome of /mcp/login, not a fault,
but the servlet logged two of them with a full stack trace:

- checkIfLoginBlocked's AuthenticationException was logged as
  LOG.warn("Login blocked for user", e) — a stack dump for the lockout
  policy working as designed.
- An unknown account never reaches the AuthenticationException catch at
  all. Both authenticators report it as CustomExceptionMessage
  (BasicAuthenticator.lookUserInProvider, LdapAuthenticator.lookUserInProvider),
  so it fell through to the generic handler: ERROR + stack trace, and
  HTTP 500 instead of the login form.

Log both as events, and give the unknown-account case the same inline
"Invalid username or password" form the wrong-password case already gets.
LDAP reuses CustomExceptionMessage for an unreachable directory, so the
new catch rethrows anything that isn't INVALID_USER_OR_PASSWORD and that
still reaches the generic handler.

WebServiceException.errorType had no accessor and is the only reliable
discriminator here — LDAP reports an unknown user as 500 and a connection
failure as 503, so the status can't be used. Added the getter.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@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 backend safe to test Add this label to run secure Github workflows on PRs labels Sep 18, 2026
@gitar-bot

gitar-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk

Stops logging rejected MCP logins as exceptions by catching CustomExceptionMessage for invalid credentials and distinguishing them from real faults via errorType. Unknown accounts now return the login form inline instead of HTTP 500, while LDAP connection failures continue to reach the generic handler. Unit tests cover the new paths and verify the fix.

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

// Both authenticators report an unknown account as CustomExceptionMessage, and LDAP uses
// the same type for a directory that is unreachable. Only INVALID_USER_OR_PASSWORD is a
// rejected credential; anything else is a real fault the outer handler must still log.
if (!INVALID_USER_OR_PASSWORD.equals(e.getErrorType())) {

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.

P1 LDAP Misconfiguration Is Masked

When an LDAP entry lacks the configured username or email attribute, LdapAuthenticator reports the configuration fault with the INVALID_USER_OR_PASSWORD error type. This check then treats it as rejected credentials and renders the login form instead of reaching the generic error handler. As a result, operators receive no server error or diagnostic error log for the LDAP configuration failure. Please distinguish this case using more than errorType, or assign configuration failures a separate error type.

Knowledge Base Used: Client, SDK, and MCP integrations

@mohityadav766 mohityadav766 self-assigned this Sep 18, 2026
} catch (AuthenticationException e) {
LOG.warn("Login blocked for user", e);
// Lockout is the policy doing its job, not a fault - record the event, not a stack trace.
LOG.warn("Login blocked after repeated failed attempts");

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.

adding a username in there would be good

@mohityadav766 mohityadav766 moved this to In Review / QA 👀 in Shipping Sep 18, 2026
@sonarqubecloud

Copy link
Copy Markdown

@mohityadav766
mohityadav766 added this pull request to the merge queue Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit b5d520a03374796573718770dd4d44936ab374cf in Playwright run 35382894115, attempt 1.

✅ 4486 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 51m 22s

⏱️ Max setup 4m 49s · max shard execution 22m 6s · max shard-job elapsed before upload 25m 29s · reporting 19s

🌐 220.97 requests/attempt · 2.23 app boots/UI scenario · 40.95% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 40.95% (convergence target: at most 15%).
  • Browser traffic was 220.97 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10673 boots / 4785 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
✅ Shard chromium-01 160 0 0 0 0 0
✅ Shard chromium-02 173 0 0 0 0 0
🟡 Shard chromium-03 160 0 1 0 0 0
✅ Shard chromium-04 247 0 0 0 0 0
✅ Shard chromium-05 192 0 0 0 0 0
✅ Shard chromium-06 156 0 0 0 0 0
✅ Shard chromium-07 187 0 0 0 0 0
🟡 Shard chromium-08 159 0 2 0 0 0
🟡 Shard chromium-09 174 0 1 0 0 0
🟡 Shard chromium-10 178 0 1 0 0 0
✅ Shard chromium-11 191 0 0 0 0 0
✅ Shard chromium-12 163 0 0 0 0 0
✅ Shard chromium-13 184 0 0 1 0 0
🟡 Shard chromium-14 204 0 1 0 0 0
✅ Shard chromium-15 209 0 0 0 0 0
🟡 Shard chromium-16 167 0 1 0 0 0
✅ Shard chromium-17 179 0 0 0 0 0
🟡 Shard chromium-18 173 0 1 0 0 0
✅ Shard chromium-19 162 0 0 0 0 0
🟡 Shard chromium-20 164 0 1 0 0 0
🟡 Shard chromium-21 165 0 1 0 0 0
✅ Shard chromium-22 177 0 0 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 80 0 0 0 0 0
✅ Shard import-export-02 70 0 0 0 0 0
✅ Shard ingestion-01 43 0 0 0 0 0
✅ Shard ingestion-02 55 0 0 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 10 flaky test(s) (passed on retry)
  • Features/UserProfileOnlineStatus.spec.ts › Should not show online status for inactive users (shard chromium-03, 1 retry)
  • Features/ColumnBulkOperations.spec.ts › should load the page with stats cards and grid data (shard chromium-08, 1 retry)
  • Features/ColumnBulkOperations.spec.ts › should show no results when searching for nonexistent column (shard chromium-08, 1 retry)
  • Pages/DataContracts.spec.ts › Add and update Security and SLA tabs (shard chromium-09, 1 retry)
  • Features/ActivityFeed.spec.ts › All badge, header and rendered list agree on the count (shard chromium-10, 1 retry)
  • Features/AIMode/CustomPropertiesPanel.spec.ts › deletes a custom property via the confirmation modal (shard chromium-14, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-16, 1 retry)
  • Flow/AddRoleAndAssignToUser.spec.ts › Verify assigned role to new user (shard chromium-18, 1 retry)
  • Pages/ExploreTree.spec.ts › Copy field link button should copy the field URL to clipboard for APIEndpoint (shard chromium-20, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Text formatting (shard chromium-21, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-18T23:29:58Z)

Blocked the queue: playwright-summary

@ShaileshParmar11
ShaileshParmar11 added this pull request to the merge queue Sep 19, 2026
Merged via the queue into main with commit 401b7f7 Sep 19, 2026
175 of 177 checks passed
@ShaileshParmar11
ShaileshParmar11 deleted the suppress-invalid-creds-logging branch September 19, 2026 06:12
@github-project-automation github-project-automation Bot moved this from In Review / QA 👀 to Done ✅ in Shipping Sep 19, 2026

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

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

Projects

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

3 participants