Potential fix for code scanning alert no. 23: Incomplete string escaping or encoding #1662
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/E2OpenPlugins/e2openplugin-OpenWebif/security/code-scanning/23
To fix the incomplete escaping, both backslashes (
\
) and single quotes ('
) must be escaped in the string, in that order (to avoid double-escaping the backslashes introduced during quote escaping). The best way to do this is to first replace every backslash (\
) with a double backslash (\\
), and then replace every single quote ('
) with a backslash-single-quote (\'
). This ensures that any existing backslashes do not interfere with the escaping of single quotes, and that the resulting string is safe to insert into a single-quoted JavaScript or HTML attribute. The changes only need to be made in the region wheredesc.replace(/'/g,"\\'")
is currently used (line 774). No new libraries are needed, and the code remains functionally unchanged except for the more robust escaping.Suggested fixes powered by Copilot Autofix. Review carefully before merging.