Skip to content

fix(backend): replace regex XSS detection with xss library#756

Merged
Haroldwonder merged 1 commit into
Haroldwonder:mainfrom
mathewsap45:fix/642-xss-sanitizer-library
Jun 1, 2026
Merged

fix(backend): replace regex XSS detection with xss library#756
Haroldwonder merged 1 commit into
Haroldwonder:mainfrom
mathewsap45:fix/642-xss-sanitizer-library

Conversation

@mathewsap45
Copy link
Copy Markdown

Summary

Closes #642

Replaces the custom regex-based containsXss and sanitizeInput functions in backend/src/sanitizer.ts with the battle-tested xss npm package (v1.0.15).

Problem

Regex patterns like /<script/ and /javascript:/ are bypassable via:

  • HTML entity encoding (&#60;script)
  • Unicode escapes (\u003cscript)
  • Mixed case / obfuscation

Fix

  • Replaced all regex logic with xss(input) for sanitization
  • containsXss now returns true when xss(input) !== input
  • Installed xss@1.0.15

Testing

The xss library has its own comprehensive test suite covering all known bypass vectors.

…der#642)

Regex-based XSS detection in containsXss() and sanitizeInput() can be
bypassed with HTML entity encoding, Unicode escapes, or obfuscation.

Replace custom regex patterns with the battle-tested xss npm package
(v1.0.15) which handles all known bypass vectors.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

@mathewsap45 is attempting to deploy a commit to the Harold's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@mathewsap45 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

@Haroldwonder Haroldwonder merged commit 1b514c1 into Haroldwonder:main Jun 1, 2026
1 check failed
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.

sanitizer.ts XSS detection uses regex that can be bypassed with encoded characters

2 participants