Potential fix for code scanning alert no. 28: Incomplete string escaping or encoding#6140
Merged
Potential fix for code scanning alert no. 28: Incomplete string escaping or encoding#6140
Conversation
…ing or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #6140 +/- ##
==========================================
Coverage 50.00% 50.01%
Complexity 7481 7481
==========================================
Files 722 722
Lines 24100 24100
==========================================
+ Hits 12052 12053 +1
+ Misses 12048 12047 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Potential fix for https://github.com/Catrobat/Catroweb/security/code-scanning/28
In general, to fix this issue you should avoid hand-rolled partial escaping when embedding arbitrary strings into query selectors, and instead either (a) avoid string concatenation by using attribute-aware DOM APIs, or (b) correctly escape all special characters, including backslashes, using a robust method.
The best fix here, without changing functionality, is to stop building the selector string with an interpolated attribute value and instead select the category element using
querySelectorwith an attribute-only selector (assumingdata-namevalues are known beforehand), or more robustly, usequerySelectorAlland comparedataset.namein code. However, that would be a functional change. A minimal, targeted fix that preserves current behavior is to escape both backslashes and double quotes infile.categoryin the correct order: first escape backslashes (\→\\), then escape double quotes ("→\"). This prevents existing backslashes from interfering with the escaping of quotes and ensures the resulting selector string is well-formed.Concretely, in
assets/MediaLibrary/MediaLib.js, around line 174, change:to something that first escapes backslashes globally, then escapes quotes globally, for example:
No new imports or external libraries are needed, and this keeps the logic and usage of
catEscapedidentical while fixing the incomplete escaping.Suggested fixes powered by Copilot Autofix. Review carefully before merging.