open-context open-context
October 23, 2026 · 6 min read

How open-context Redacts Database Credentials in Logs

open-context never writes a raw database password to a log line, API response, or the dashboard. Every connection string it accepts — across all 15 supported context-store backends — is parsed into three forms: a raw string used only to open the connection, a canonical string the driver actually consumes, and a redacted string with every credential replaced by *** that is the only one ever logged, returned over HTTP, or shown in the UI.

Key takeaways

  • open-context's DSN parser splits every connection string into raw, canonical, and redacted forms — only redacted ever reaches a log, API response, or the UI.
  • Masking covers the password half of user:password@host and any query parameter named token, password, apikey, api_key, or authtoken.
  • Drivers connect with canonical, not raw — it preserves scheme details like rediss:// and mongodb+srv:// that change how the connection actually behaves.
  • This is a project-wide invariant, not a convenience for one backend: every one of the 15 BYODB adapters is expected to satisfy it, and the conformance suite treats it as part of the contract.
  • It mirrors established guidance — CWE-532 names secrets in log files as its own weakness class, and OWASP's Logging Cheat Sheet recommends masking sensitive values before they're written anywhere.

Why connection string secrets end up in logs anyway

A database connection string is usually treated as one opaque token: postgres://user:password@host:5432/db. It gets handed to a driver, printed in a startup banner, echoed back in an error message when the connection fails, or surfaced in a "current database" status line somewhere in a dashboard. Any one of those ordinary code paths can put a plaintext password somewhere it was never meant to be.

This isn't a hypothetical. MITRE's CWE-532, "Insertion of Sensitive Information Into Log File", exists precisely because this mistake recurs across unrelated codebases: once a credential lands in a log, it's exposed to anyone with log access, and log storage is routinely less locked down than the system the credential protects. OWASP's Logging Cheat Sheet gives the standard remedy — mask, sanitize, or otherwise avoid writing secrets to logs in the first place, rather than trying to scrub them out after the fact.

How open-context parses and redacts a connection string

Three strings, one DSN

open-context's parseDsn(), in src/store/dsn.ts, is the single place a connection string enters the system — whether it comes from the OPENCONTEXT_DB_URL environment variable, a config file, or the legacy OPENCONTEXT_STORE_PATH setting. It returns one object with three related strings:

{
  raw:       "postgres://admin:[email protected]:5432/opencontext",
  canonical: "postgres://admin:[email protected]:5432/opencontext",
  redacted:  "postgres://admin:***@db.internal:5432/opencontext"
}

raw is handed only to the driver that opens the connection. canonical rewrites the scheme to whatever spelling the underlying client library actually expects — important because open-context accepts friendlier aliases like mongo:// or valkey:// that a real MongoDB or Redis client would reject outright. redacted is what everything else in the codebase is allowed to touch.

What actually gets masked

redactDsn() does two things to a connection string. First, it replaces the password half of a user:password@host authority with ***. Second, it walks the query string and masks the value of any parameter named token, password, apikey, api_key, or authtoken — covering the common ways backends like Cloudflare D1 or DynamoDB pass an API token instead of a password:

// before
d1://ACCOUNT_ID/DATABASE_ID?apiToken=abcd1234secret

// after redactDsn()
d1://ACCOUNT_ID/DATABASE_ID?apiToken=***

Usernames, hosts, ports, and database names stay visible — they're useful for debugging and aren't secrets by themselves. A string open-context can't parse is returned unchanged rather than thrown on, since redactDsn() is a display helper and must never be the thing that breaks a status page.

Where redaction is enforced, not just available

Having a redacted field only matters if nothing else ever gets logged or displayed instead. open-context routes every user-visible surface through it: the /status endpoint in src/server.ts returns resolveDatabase().redacted as the store identifier, the Dashboard's database indicator shows the same redacted string, and the npm run db -- status CLI command prints it rather than the connection string you actually configured. The raw string only ever travels from the environment variable or config file to the driver that needs it — never to a response body, a terminal log, or a React component.

Preserving the invariant across 15 backends — and the next one

open-context's BYODB layer implements CRUD once per adapter family (file, SQL, document/KV, multi-model) rather than once per backend, and redaction gets the same treatment: it's written once in dsn.ts, not copy-pasted into 15 separate drivers where one of them could eventually forget. CLAUDE.md states this as a hard invariant for the project — "credentials never leak: everything user-visible goes through redactDsn()" and "drivers pass dsn.canonical, never dsn.raw" — and the steps for adding a 16th backend include parsing its backend-specific fields into the same ParsedDsn shape, so a new driver inherits redaction automatically instead of needing its own.

That centralization is also what makes the behavior testable: the same conformance suite that checks ordering and search semantics identically across SQLite, Postgres, and the rest can assert that a backend's status output never contains a password — one test, enforced everywhere, instead of fifteen chances to get it wrong. If you're also thinking about what's exposed once a backend is running, the write-up on securing a local MCP server covers the rest of that surface.

Point open-context at any of its 15 supported databases without ever worrying what shows up in a log.

Get started with open-context →

FAQ

Does open-context ever log my database password?

No. open-context parses every connection string into a redacted form with passwords and secret query parameters replaced by ***, and only that redacted form is ever written to a log line, returned from the HTTP API, or shown in the UI.

What's the difference between a DSN's raw, canonical, and redacted forms?

raw is the original string with credentials intact and is only ever handed to the database driver that needs to connect. canonical is the same string with its scheme normalized to the exact spelling a driver library expects, such as rediss:// or mongodb+srv://. redacted masks every credential and is the only form safe to log, return over HTTP, or display in the UI.

Which parts of a connection string get masked?

The password segment of a user:password@host authority is replaced with ***, and any query parameter named token, password, apikey, api_key, or authtoken has its value replaced with ***. The username, host, port, and database name are left visible since they aren't secrets on their own.

Does redaction protect against a stolen database password?

No. Redaction only stops open-context's own logs, API responses, and UI from displaying a credential in plain text. It doesn't replace rotating leaked credentials, restricting network access to your database, or securing the database server itself.

Do I need to configure anything to get this protection?

No. Redaction is automatic for every connection string parsed by open-context, whether it comes from OPENCONTEXT_DB_URL, the legacy OPENCONTEXT_STORE_PATH, or a config file, and it applies the same way across all 15 supported database backends.