JS: fix js/double-escaping displaying empty metachar#19840
Closed
Napalys wants to merge 2 commits intogithub:mainfrom
Closed
JS: fix js/double-escaping displaying empty metachar#19840Napalys wants to merge 2 commits intogithub:mainfrom
js/double-escaping displaying empty metachar#19840Napalys wants to merge 2 commits intogithub:mainfrom
Conversation
21981a5 to
466eac3
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes how backslash metacharacters are displayed in the js/double-escaping query alerts to prevent empty output.
- Update alert message construction to escape backslashes before concatenation
- Adjust test expectations to match the new escaped output
- Add a change note documenting the backslash display fix
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| javascript/ql/test/query-tests/Security/CWE-116/DoubleEscaping/DoubleEscaping.expected | Updated expected alert output to show \\ as \\\\ in test harness |
| javascript/ql/src/change-notes/2025-06-23-double-escaping.md | Added note about correct backslash display in alerts |
| javascript/ql/src/Security/CWE-116/DoubleEscaping.ql | Changed message construction to call metachar.replaceAll("\\", "\\\\") before concatenation |
Comment on lines
126
to
+134
| primary.escapes(metachar, _) and | ||
| supplementary = primary.getAnEarlierEscaping(metachar) and | ||
| message = "may double-escape '" + metachar + "' characters from $@" | ||
| message = "may double-escape '" + metachar.replaceAll("\\", "\\\\") + "' characters from $@" | ||
| or | ||
| primary.unescapes(_, metachar) and | ||
| supplementary = primary.getALaterUnescaping(metachar) and | ||
| message = "may produce '" + metachar + "' characters that are double-unescaped $@" | ||
| message = | ||
| "may produce '" + metachar.replaceAll("\\", "\\\\") + | ||
| "' characters that are double-unescaped $@" |
There was a problem hiding this comment.
[nitpick] Consider extracting the metachar.replaceAll("\\", "\\\\") call into a local variable (e.g. displayMetachar) to improve readability and avoid repeating this expression in both message branches.
asgerf
requested changes
Jun 23, 2025
Contributor
asgerf
left a comment
There was a problem hiding this comment.
The bug is either in code scanning or the SARIF exporter, not in the CodeQL query. Backslashes have no special meaning in the message generated from QL.
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.
This pull request resolves an issue where
js/double-escapingwould display an emptymetacharin the alert message, potentially causing confusion.I have verified the fix in this repository: