Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code scanning alert no. 1: Bad HTML filtering regexp #80

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

srugano
Copy link
Contributor

@srugano srugano commented Dec 18, 2024

Fixes https://github.com/unicef/hope-country-report/security/code-scanning/1

To fix the problem, we need to update the regular expression used to match the end of HTML comments to account for the --!> variant. This can be done by modifying the inBlock function to recognize both --> and --!> as valid end tags for comments.

  • Update the inBlock function to handle both --> and --!> as valid end tags for comments.
  • Modify the relevant lines in the inText function to use the updated inBlock function.

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>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
else return null;
} else if (stream.match("--")) {
return chain(inBlock("comment", "-->"));
return chain(inBlock("comment", /-->/, /--(?:!>)/));

Check failure

Code scanning / CodeQL

Bad HTML filtering regexp High

This regular expression only parses --> and not --!> as a HTML comment end tag.

Copilot Autofix AI 23 days ago

To fix the problem, we need to update the regular expression used to match the end of HTML comments to account for the alternative valid end tag --!>. This can be done by modifying the regular expression to match both --> and --!>. The best way to fix this without changing existing functionality is to update the regular expression on line 82.

Suggested changeset 1
src/hope_country_report/apps/power_query/static/admin/power_query/codemirror/xml.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/hope_country_report/apps/power_query/static/admin/power_query/codemirror/xml.js b/src/hope_country_report/apps/power_query/static/admin/power_query/codemirror/xml.js
--- a/src/hope_country_report/apps/power_query/static/admin/power_query/codemirror/xml.js
+++ b/src/hope_country_report/apps/power_query/static/admin/power_query/codemirror/xml.js
@@ -81,3 +81,3 @@
         } else if (stream.match("--")) {
-          return chain(inBlock("comment", /-->/, /--(?:!>)/));
+          return chain(inBlock("comment", /-->/, /--(?:!>|>)/));
         } else if (stream.match("DOCTYPE", true, true)) {
EOF
@@ -81,3 +81,3 @@
} else if (stream.match("--")) {
return chain(inBlock("comment", /-->/, /--(?:!>)/));
return chain(inBlock("comment", /-->/, /--(?:!>|>)/));
} else if (stream.match("DOCTYPE", true, true)) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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.

1 participant