Skip to content

[codex] Harden input sanitization#296

Closed
lisamariet wants to merge 1 commit into
Liquifact:mainfrom
lisamariet:codex/liquifact-prototype-pollution-hardening
Closed

[codex] Harden input sanitization#296
lisamariet wants to merge 1 commit into
Liquifact:mainfrom
lisamariet:codex/liquifact-prototype-pollution-hardening

Conversation

@lisamariet

Copy link
Copy Markdown

Summary

  • Harden sanitizeValue() against nested prototype-pollution payloads by dropping __proto__, constructor, and prototype keys recursively.
  • Return sanitized objects with a null prototype so downstream object spreads and Knex filter construction cannot inherit polluted properties.
  • Bound recursive traversal for large arrays and objects while preserving existing string normalization behavior.
  • Add focused utility and middleware coverage for JSON-parsed malicious keys, nested array payloads, query sanitization, global prototype safety, and traversal caps.
  • Document the request sanitization behavior in the README security notes.

Why

Issue #284 asks for deeper prototype-pollution protection in request sanitization before downstream handlers build filters or spread request data. The previous sanitizer removed some dangerous keys, but it still returned regular objects and did not cap array/object traversal.

Validation

  • npx jest src/utils/sanitization.test.js src/middleware/sanitizeInput.test.js --runInBand --forceExit
  • npx eslint src/utils/sanitization.js src/utils/sanitization.test.js src/middleware/sanitizeInput.js src/middleware/sanitizeInput.test.js
  • git diff --check HEAD~1..HEAD

Baseline note

Full npm test and full npm run lint currently fail on unrelated pre-existing repository baseline issues outside this patch. The focused sanitizer tests and focused ESLint checks above pass.

Drop prototype-polluting keys recursively, return null-prototype sanitized objects, and bound traversal for oversized payloads. Add focused tests for JSON-parsed pollution keys and middleware behavior.
@lisamariet lisamariet closed this Jun 21, 2026
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