Skip to content

fix(sanitize): stop rewriting values, narrow injection checks, fix prototype pollution - #1127

Closed
devbigaiizen wants to merge 1 commit into
Heliobond:mainfrom
devbigaiizen:fix/issue-853-sanitize-inputs
Closed

devbigaiizen wants to merge 1 commit into
Heliobond:mainfrom
devbigaiizen:fix/issue-853-sanitize-inputs

Conversation

@devbigaiizen

Copy link
Copy Markdown
Contributor

Issue
sanitizeInputs has three defects. It silently strips HTML tags from body strings, so "output < 50kW" loses text with no error or log. The SQL and command injection regexes reject ordinary prose ("don't do this -- see docs", "${...}"). And the object builder assigns result[k], so a proto key from JSON.parse invokes the prototype setter and replaces the result's prototype, which lets downstream key in obj checks see attacker fields as present.

Changes

  • sanitizeString no longer rewrites values. It validates and returns the value unchanged, so body and query now behave the same.
  • The SQL regex no longer rejects bare -- or /*, and the tautology pattern now needs a digit or a quoted value with an equals sign after or/and.
  • The command regex no longer rejects ${...}, a common template placeholder in stored text. Backticks and $(...) are still rejected.
  • Object copying uses Object.defineProperty, so proto lands as an own data property and the prototype is untouched.
  • validation.ts checks required and property fields with hasOwnProperty instead of in, so inherited fields never satisfy a check.

Noticed

  • The length, array and depth caps are unchanged, and path traversal is still rejected.
  • Real injection patterns are still rejected: '; DROP TABLE', ' OR 1=1, UNION SELECT, backticks, $(...).
  • The old test that expected tag stripping is updated to expect pass-through.

Tests

  • sanitize suite: 10 passed, 0 failed (5 existing plus 5 new, with the strip test updated).
  • New tests cover "50 < 60" unchanged, prose with -- and ${...} passing, real SQLi and command injection still rejected, proto not polluting the prototype, body and query consistent.
  • validation suites: 32 passed, 0 failed.
  • tsc --noEmit clean, eslint clean (0 errors), prettier clean.

Closes #853

@drips-wave

drips-wave Bot commented Nov 25, 2026

Copy link
Copy Markdown

@devbigaiizen Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

// defineProperty, not assignment: assigning "__proto__" would invoke
// the prototype setter and replace result's prototype. As an own data
// property it stays inert and cannot affect downstream validation.
Object.defineProperty(result, k, {
@devbigaiizen

devbigaiizen commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing this one in favour of #1129, which covers all four issues in a single PR. The fix here is included in it unchanged.

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.

sanitizeInputs silently corrupts strings, overblocks legitimate input, and can pollute req.body's prototype

2 participants