Skip to content

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

Merged
earlution merged 1 commit into
mainfrom
alert-autofix-12
May 22, 2026
Merged

Potential fix for code scanning alert no. 12: Bad HTML filtering regexp#5
earlution merged 1 commit into
mainfrom
alert-autofix-12

Conversation

@earlution

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/earlution/6-axis-compass/security/code-scanning/12

Use a more robust script-block match that is case-insensitive and tolerant of attributes, and apply the same pattern consistently where script extraction/replacement happens.

Best single fix in this snippet:

  • In scripts/build.js, update the regex used at line 133 (html.match(...)) and line 140 (.replace(...)) from a strict lowercase <script>...</script> matcher to a case-insensitive matcher that accepts optional attributes:
    • /<script\b[^>]*>([\s\S]*?)<\/script\s*>/i for extraction (capturing body).
    • /<script\b[^>]*>[\s\S]*?<\/script\s*>/i for replacement.
  • This keeps existing functionality (first script block only, non-global behavior) while fixing uppercase/mixed-case handling and making matching less fragile.

No new methods/imports/dependencies are required.

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>
Comment thread scripts/build.js
} catch (_) {}

const moduleMatch = html.match(/<script>([\s\S]*?)<\/script>/);
const moduleMatch = html.match(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/i);
Comment thread scripts/build.js
const output = html
.replace(/<style>[\s\S]*?<\/style>/, `<style>\n${css}\n</style>`)
.replace(/<script>[\s\S]*?<\/script>/, `<script>\n${js}\n</script>`)
.replace(/<script\b[^>]*>[\s\S]*?<\/script\s*>/i, `<script>\n${js}\n</script>`)
@earlution earlution marked this pull request as ready for review May 22, 2026 15:10
@earlution earlution merged commit c8241a1 into main May 22, 2026
4 of 5 checks passed
@earlution earlution deleted the alert-autofix-12 branch May 22, 2026 15:10
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