Potential fix for code scanning alert no. 4: Incomplete string escaping or encoding#214
Merged
Conversation
…ng or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: ALifeInArtifyAI <238904666+projectedanx@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Code Review
This pull request updates the 'query_string' function in 'js/tablesorte.js' to use a more comprehensive regular expression for escaping special characters in the query string key. The reviewer suggested adding a defensive check to ensure 'key' is a string before calling '.replace()' to prevent potential runtime 'TypeError' crashes.
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/projectedanx/YOURLS/security/code-scanning/4
The best fix is to replace the partial/manual escaping with a correct global regex-escaping step before constructing
RegExp.In
js/tablesorte.js, insidequery_string(key), replace:key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");with:
key = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");This is the standard safe pattern for escaping all regex metacharacters, not just the first
[and]. It preserves existing functionality (matching the requested query-string key) while removing incomplete escaping risk and handling broader edge cases correctly. No new imports or dependencies are needed.Suggested fixes powered by Copilot Autofix. Review carefully before merging.