JavaScript: Reduce FPs in js/incomplete-sanitization for regex escaping#9
Open
kiro-agent[bot] wants to merge 1 commit into
Open
JavaScript: Reduce FPs in js/incomplete-sanitization for regex escaping#9kiro-agent[bot] wants to merge 1 commit into
kiro-agent[bot] wants to merge 1 commit into
Conversation
Owner
|
/kiro fix this by adding/updating test cases as well! |
f37dc17 to
16a6cb6
Compare
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 was created by @kiro-agent on behalf of @mrigankpawagi 👻
Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro Web
Summary
This PR reduces false positives in the
js/incomplete-sanitizationquery by excluding the "does not escape backslash characters" warning for cases where the replace call is escaping regex metacharacters forRegExpconstruction or escaping quotes for template literal interpolation.Problem
MRVA on the top-100 JavaScript repositories produced 208 alerts, of which 99 (48%) were "This does not escape backslash characters in the input." Analysis of these alerts revealed two dominant false positive patterns:
Pattern 1: Regex metacharacter escaping (~60% of backslash FPs)
These are escaping regex special characters for
new RegExp()construction. They don't need to also escape backslashes because the context is regex construction, not security sanitization.Pattern 2: Quote escaping for string interpolation (~20% of backslash FPs)
`"${title.replace(/"/g, '\\"')}"`These escape quotes for embedding in string templates. The input is typically known content (like titles/descriptions) that won't contain backslashes.
Changes
Added two new predicates to
IncompleteSanitization.ql:isRegExpMetacharEscape- Excludes backslash-escape warnings when the matched character is a regex metacharacter ($,[,],(,),.,+,*,?,^,|,/) and the result flows to aRegExpconstructor or the escaping only targets non-security-relevant characters.isQuoteEscapeForInterpolation- Excludes backslash-escape warnings when the matched character is"and the result is used in a template literal.MRVA Validation
\or'or"in HTML/SQL contexts) remain flaggedExamples of eliminated false positives
local.replace(/\$/g, '\\$')RegExpstr.replace(/"/g, '\\"')in templatereStr.replace(/\[/g, '\\[')RegExppath.replace('\\', '/')