Potential fix for code scanning alert no. 10: Incomplete multi-character sanitization #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/DataScience-GT/query/security/code-scanning/10
In general, the best fix is to stop relying on ad‑hoc regular expressions for HTML/script sanitization and use a vetted library designed for XSS prevention. This eliminates the multi‑character sanitization pitfall and a large class of bypasses. For a Node/TypeScript backend,
sanitize-htmlis a common, well‑maintained choice that already handles<script>tags, dangerous attributes, URIs, and malformed markup.Concretely, within
sanitizeInput’s string branch (lines 39–57), we should:sanitize-htmlat the top of the file.do { ... } whileblock that chains.replace(...)calls with a single call tosanitizeHtml, possibly configured to be reasonably strict (e.g., a default or minimal allowlist).trim()andslice(0, 10000)), to avoid changing downstream behavior beyond security hardening.We will only modify code inside
packages/api/src/middleware/security.ts:sanitize-html.sanitizeHtml(String(input))and then trim/slice the result as before.No other behavior (arrays, objects, validators, rate limiting) will be changed.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.