Skip to content

Potential fix for code scanning alert no. 8: Bad HTML filtering regexp - #5

Merged
PRATHAM777P merged 1 commit into
mainfrom
alert-autofix-8
Apr 27, 2026
Merged

PRATHAM777P merged 1 commit into
mainfrom
alert-autofix-8

Conversation

@PRATHAM777P

Copy link
Copy Markdown
Owner

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 hardens style/noscript handling 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.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@PRATHAM777P
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, "")
@PRATHAM777P
PRATHAM777P merged commit 6d6b16e into main Apr 27, 2026
1 of 2 checks passed
@PRATHAM777P
PRATHAM777P deleted the alert-autofix-8 branch April 27, 2026 18:21
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.

2 participants