Potential fix for code scanning alert no. 4: Incomplete string escaping or encoding#8
Merged
Merged
Conversation
…ng or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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/jonathansantilli/codegate/security/code-scanning/4
In general, to fix incomplete escaping when using
String.prototype.replace, you should either (1) use a regular expression with the global (g) flag so that all occurrences are replaced, or (2) use an appropriate, well-tested encoder/escaping function (for URLs,encodeURIComponentorencodeURIas appropriate).For this specific case, we want to correctly encode all
/characters in npm scoped package locators that start with@. The current implementation:replaces only the first
/. The minimal, behavior-preserving fix is to change.replace("/", "%2f")to.replace(/\//g, "%2f"), which escapes every/in the locator when it’s scoped. This retains the existing structure of the code, does not alter behavior for typical valid locators (which only contain one/), and correctly handles any additional slashes in edge cases. No new imports are needed; we only adjust the replace call inendpointForinsrc/layer3-dynamic/resource-fetcher.tsaround line 48–53.Suggested fixes powered by Copilot Autofix. Review carefully before merging.