Skip to content

docs: add security-patterns.md (Mongoose CodeQL sanitizers) - #421

Merged
samxu01 merged 1 commit into
mainfrom
docs/mongoose-codeql-sanitizer-patterns
May 22, 2026
Merged

samxu01 merged 1 commit into
mainfrom
docs/mongoose-codeql-sanitizer-patterns

Conversation

@samxu01

@samxu01 samxu01 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

New docs/security-patterns.md that captures the patterns CodeQL's js/sql-injection + js/nosql-injection queries accept as sanitizers, plus the anti-patterns that look safe but fail review.

Why

Code-review feedback on PR #413 (the phantom-directive validation) flagged:

A pattern doc or skill for "user-tainted string into Mongoose filter" is worth adding. The five CodeQL iterations on this single PR are a cost that future authors will pay again. The install.ts:114-119 pattern is the right reference, but it's buried.

This doc surfaces three patterns + four anti-patterns drawn from the two recent battles:

Test plan

  • CI green (doc-only change, no code)
  • Mintlify deploy renders the new page (it's a .md under docs/ — should be picked up automatically)
  • Linkable from future PR reviews when CodeQL flags a Mongoose filter

🤖 Generated with Claude Code

Captures the patterns CodeQL's js/sql-injection and js/nosql-injection
queries accept as sanitizers, plus the anti-patterns. Backed by the
two recent PRs:

- PR #408 — String + replace + roundtrip + test gate (canonical
  scalar-field sanitizer pattern). Used in install.ts:114-119.
- PR #413 — ObjectId.isValid + cast (canonical ObjectId-field
  sanitizer). The 5-iteration CodeQL battle that drove the
  in-memory-Set refactor for user-tainted regex captures is also
  documented as the case where the standard sanitizer chain isn't
  enough and the right move is to remove the tainted value from
  the query entirely.

Suggested by code-review feedback on PR #413: 'a pattern doc or
skill for user-tainted string into Mongoose filter is worth adding.
The five CodeQL iterations on this single PR are a cost that
future authors will pay again.'
@samxu01
samxu01 marked this pull request as ready for review May 22, 2026 10:00
@samxu01
samxu01 merged commit 6b34eaa into main May 22, 2026
9 checks passed
@samxu01
samxu01 deleted the docs/mongoose-codeql-sanitizer-patterns branch May 22, 2026 10:00
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.

1 participant