Skip to content

security: address code scanning and secret scanning alerts#25

Merged
rathboma merged 2 commits into
mainfrom
security/fix-code-scanning-alerts
May 8, 2026
Merged

security: address code scanning and secret scanning alerts#25
rathboma merged 2 commits into
mainfrom
security/fix-code-scanning-alerts

Conversation

@rathboma
Copy link
Copy Markdown
Contributor

@rathboma rathboma commented May 8, 2026

Summary

Triaged the open GitHub code scanning and secret scanning alerts and fixed the legitimate ones.

Code scanning

  • actions/missing-workflow-permissions (#28, #32): added an explicit top-level permissions: contents: read block to test.yml and publish.yml. The publish job gets contents: write since it cuts a GitHub Release.
  • js/clear-text-logging in packages/postgres-server/src/protocol-handler.ts (Bump lodash from 4.17.21 to 4.18.1 #21deps: clear open Dependabot alerts #26): the parsed client message can carry a password (type: 'password', string: <password>) or credential-bearing SQL (CREATE USER ... PASSWORD '...'). Replaced raw debug('…', message) / debug('…', queryString) calls with a small redactMessage / redactSql pair that masks the password field and any literal PASSWORD '…' / IDENTIFIED BY clauses before they reach the debug stream. The startup-message debug line that dumped the whole struct now just says Startup message received; the actual user/database is already logged sanitized one line later.
  • js/clear-text-logging in packages/lib/src/parser.ts (Fix: non-primary snake_case ObjectId fields not converted (issue #12) #16, Bump yauzl from 3.2.0 to 3.2.1 #17, #34, #35): wrapped the parser's debug('queryleaf:parser') logger with the same SQL redaction so SQL passed in by callers can't leak literal credentials through debug output.
  • js/clear-text-logging in packages/postgres-server/tests/integration/minimal*.test.ts (Bump yaml from 2.7.0 to 2.8.3 #19, Bump picomatch from 2.3.1 to 2.3.2 #20): the mock QueryLeaf was logging the full incoming query string. Switched to logging the length only.
  • js/insecure-randomness in packages/postgres-server/src/protocol-handler.ts:1065 (Bump qs from 6.15.1 to 6.15.2 #27): the BackendKeyData secret authenticates CancelRequest messages, so it must be unguessable. Switched both the process ID and secret key to crypto.randomInt.

Secret scanning

Both alerts were placeholder Atlas URIs in blog posts that nonetheless match the Atlas URI detector:

  • docs/blog/posts/mongodb-atlas-cloud-deployment-management.md: switched to <user>:<pass> placeholders inside the SQL sample.
  • docs/blog/posts/mongodb-vector-search-ai-applications-semantic-similarity.md and docs/blog/posts/mongodb-gridfs-file-management-sql.md: switched the JS samples to read process.env.MONGODB_URI, which is what we'd recommend in real code anyway.

Already-dismissed / not addressed

  • #33 js/polynomial-redos — already dismissed.
  • All other alerts (js/hardcoded-credentials, the workflow permissions on ci.yml, lib parser fixed, etc.) are already in the fixed state.

Test plan

  • yarn typecheck
  • yarn workspace @queryleaf/lib test:unit
  • yarn workspace @queryleaf/postgres-server test:unit
  • yarn workspace @queryleaf/lib build and yarn workspace @queryleaf/postgres-server build
  • CI green
  • Confirm code scanning re-runs and clears the listed alerts

- Add explicit `permissions: contents: read` to test.yml and publish.yml
  workflows. Grant `contents: write` on the publish job for releases.
- Redact password / SQL payloads in protocol-handler debug logs so
  the password message and credential-bearing SQL never hit clear-text
  output. Same redaction applied to lib/parser.ts logging.
- Replace Math.random() with crypto.randomInt for the backend secret
  key in BackendKeyData — that key authenticates CancelRequest, so it
  needs to be unguessable.
- Stop logging full SQL strings in postgres-server integration test
  mocks; log query length only.
- Replace `mongodb+srv://username:password@cluster.mongodb.net` style
  placeholders in three blog posts so they no longer trip the Atlas
  URI secret scanner. Switched code samples to env vars and the SQL
  sample to `<user>:<pass>` placeholders.
Comment thread packages/postgres-server/tests/integration/minimal-integration.test.ts Dismissed
Comment thread packages/postgres-server/tests/integration/minimal.integration.test.ts Dismissed
Pull the credential-masking regex into packages/lib/src/redact.ts and
re-export it from the lib's public surface so postgres-server can pull
it in instead of carrying its own copy.

Also extend the basic.test.ts mock to spread the real module before
overriding QueryLeaf, otherwise the new redactSql import resolves to
undefined inside the handler under test.
@rathboma rathboma merged commit d9b03f8 into main May 8, 2026
6 checks passed
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