Skip to content

Add redacted URI diagnostics to /healthz - #254

Merged
jaredwray merged 2 commits into
mainfrom
cursor/healthz-uri-diagnostics-b4c3
Oct 20, 2026
Merged

jaredwray merged 2 commits into
mainfrom
cursor/healthz-uri-diagnostics-b4c3

Conversation

@jaredwray

@jaredwray jaredwray commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix. GET /healthz shows redacted URI diagnostics when MongoDB is configured.

Why

Production /healthz still returns MongoParseError Invalid connection string after password resets. The response now shows the URI shape without the password or the full URI.

bins.uri includes:

  • total length
  • leading whitespace, trailing whitespace, a newline, and quote marks
  • the count of @
  • the host (text after the last @ before the first / or ?)
  • the username
  • the password length
  • raw reserved characters in the password (@ : / ? # [ ] $)
  • whether the password contains %

An @ in the query string does not change the host. When every password character is reserved, passwordLength and passwordReserved stay empty. Those two values rebuild that password.

Code path

workerMongoUri returns the env value. It does not trim the value, and it does not join the binding with process.env. An empty string stays unset. applyWorkerMongoEnv stores that same text. pingMongoBinStore passes that text to new MongoClient. @keyv/mongo also stores the string and later passes it to MongoClient. The Worker options do not set uri or url, so they do not replace it.

The percent-encode hint is added only when the driver message already says Invalid connection string or unescaped characters. A querySrv error stays a querySrv error. An invalid scheme stays an invalid scheme. Those errors are not rewritten into a parse error.

A trailing newline does not make the driver throw Invalid connection string. A leading space or wrapping quotes throw Invalid scheme instead.

Verification

pnpm test passed: 565 tests, lines 100% (1485/1485).

Test audit

  • reports redacted URI diagnostics and hides the password protects the diagnostic fields, a query @, $, and an all-@ password. A leaked password fails it.
  • The parser-hint test protects a DNS error and a scheme error. The hint must not replace those messages.
  • The ping tests protect the /healthz body and the exact string stored by MongoClient, including a trailing newline.
  • passes MONGODB_URI through without trimming or joining text protects the Worker env path into the ping.
  • The workerd tests protect the same body on the Worker. They expect the host. They still reject the password and the full URI.

Rewritten assertions: the ping test and the two workerd tests no longer require the body to hide the host. The host is now part of the contract. The password and full-URI checks stay.

No test was deleted.

Do not merge, release, or deploy this PR.

Open in Web Open in Cursor 

The response shows length, whitespace, quotes, the @ count, the host, the username, and the password length.
It does not show the password or the full URI.
The encode hint is added only when the driver reports a parse error.

Co-authored-by: Jared Wray <me@jaredwray.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T04:00:24.615502Z ead5a94 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c8340c9) to head (8c26806).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #254   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           44        44           
  Lines         1720      1781   +61     
  Branches       386       405   +19     
=========================================
+ Hits          1720      1781   +61     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ead5a9444a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/docs/how-to-deploy/cloudflare.md Outdated
`GET /healthz` reports the bin store. A successful admin ping returns HTTP 200 and `bins.connected: true`. A failed ping returns HTTP 503 with the driver error name, a redacted message, and a code. The body has `uriPresent` (boolean) and `scheme` (`mongodb` or `mongodb+srv`). The body does not have the URI, the username, the password, or the host. On the Node server, this route reports the memory store. Connection failures are also one JSON line in the Worker logs (`mockhttp.bin-store`). Those logs use the same redaction.
`GET /healthz` reports the bin store. A successful admin ping returns HTTP 200 and `bins.connected: true`. A failed ping returns HTTP 503 with the driver error name, a redacted message, and a code. The body has `uriPresent` (boolean) and `scheme` (`mongodb` or `mongodb+srv`). On the Node server, this route reports the memory store.

When `MONGODB_URI` is set, `bins.uri` has the URI length, leading or trailing whitespace, a newline, quote marks, the `@` count, the host, the username, and the password length. The host is the text after the last `@` and before the first `/` or `?`. The body does not have the password or the full URI. The percent-encode hint is added only when the driver message is `Invalid connection string` or `unescaped characters`. A DNS error keeps the driver text. Worker logs still omit the URI, the username, the password, and the host.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Split the long diagnostics sentence

This new sentence exceeds the repository's 25-word limit for descriptive sentences. Split the field list into shorter sentences.

AGENTS.md reference: AGENTS.md:L49-L49

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The long sentence in site/docs/how-to-deploy/cloudflare.md is now four short sentences. Commit 8c26806.

Comment thread src/bin-store-diagnostics.ts Outdated
passwordHasPercent: boolean;
};

const PASSWORD_RESERVED = ["@", ":", "/", "?", "#", "[", "]"] as const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include $ in the reserved character list

When a raw $ occurs in a password, this list reports no reserved character. MongoDB requires percent encoding for $, so /healthz gives an incomplete diagnosis and omits the needed %24 fix.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

passwordReserved now includes $. The encode hint tells you to use %24. Commit 8c26806.

Comment on lines +170 to +174
atCount: uri.split("@").length - 1,
host: hostText.length > 0 ? hostText : null,
username,
passwordLength: secret === null ? null : secret.length,
passwordReserved:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid password reconstruction from public diagnostics

For mongodb://user:@@@@@host, the public response gives atCount: 5, passwordLength: 4, and passwordReserved: ["@"]. An unauthenticated caller can therefore reconstruct the complete @@@@ password, although this change states that the endpoint never returns it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When every password character is reserved, passwordLength and passwordReserved stay empty. The body does not rebuild that password. atCount still counts each @. Commit 8c26806.

Comment thread src/bin-store-diagnostics.ts Outdated
Comment on lines +147 to +150
const at = uri.lastIndexOf("@");
const after = at < 0 ? "" : uri.slice(at + 1);
const cut = after.search(/[/?]/);
const hostText = cut < 0 ? after : after.slice(0, cut);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit the delimiter search to user information

When a valid option contains @, as in ...?appName=ops@example.com, lastIndexOf selects that option instead of the user-info delimiter. MongoDB parses user information before the path and connection options, so the response reports the wrong host and password length.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The host is the text after the last @ before / or ?. An @ in the query string does not change the host. Commit 8c26806.

The host stops before the query string.
$ is a reserved password character.
A password of only reserved characters does not publish its length.

Co-authored-by: Jared Wray <me@jaredwray.com>
@jaredwray
jaredwray merged commit 17307b7 into main Oct 20, 2026
13 checks passed
@jaredwray
jaredwray deleted the cursor/healthz-uri-diagnostics-b4c3 branch October 20, 2026 04:23
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.

2 participants