Potential fix for code scanning alert no. 8: Bad HTML filtering regexp - #5
Merged
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
PRATHAM777P
marked this pull request as ready for review
April 27, 2026 18:19
Comment on lines
-42
to
+44
| .replace(/<script[\s\S]*?<\/script>/gi, "") | ||
| .replace(/<style[\s\S]*?<\/style>/gi, "") | ||
| .replace(/<noscript[\s\S]*?<\/noscript>/gi, ""); | ||
| .replace(/<script\b[\s\S]*?<\/script\b[^>]*>/gi, "") | ||
| .replace(/<style\b[\s\S]*?<\/style\b[^>]*>/gi, "") | ||
| .replace(/<noscript\b[\s\S]*?<\/noscript\b[^>]*>/gi, ""); |
Comment on lines
-42
to
+43
| .replace(/<script[\s\S]*?<\/script>/gi, "") | ||
| .replace(/<style[\s\S]*?<\/style>/gi, "") | ||
| .replace(/<noscript[\s\S]*?<\/noscript>/gi, ""); | ||
| .replace(/<script\b[\s\S]*?<\/script\b[^>]*>/gi, "") | ||
| .replace(/<style\b[\s\S]*?<\/style\b[^>]*>/gi, "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/PRATHAM777P/AlphaMind/security/code-scanning/8
General fix: avoid brittle HTML-filter regexes for script/style/noscript blocks, especially around closing tags. Prefer an HTML parser/sanitizer library; if keeping regex, make closing-tag recognition tolerant of whitespace/attributes before
>.Best minimal fix in this file: update the three block-removal regexes in
htmlToMarkdown(lines 43–45 region) so closing tags allow optional whitespace/garbage before>, e.g.</script\b[^>]*>. This directly addresses the CodeQL finding and similarly hardensstyle/noscripthandling with matching logic consistent to existing behavior.No imports or new methods are required; only regex replacements in
src/tools/fetch/web-fetch-utils.ts.Suggested fixes powered by Copilot Autofix. Review carefully before merging.