SONARJAVA-6443 Narrow S5852 to exponential backtracking and create S8786#5674
SONARJAVA-6443 Narrow S5852 to exponential backtracking and create S8786#5674pierre-loup-tristant-sonarsource wants to merge 2 commits into
Conversation
…smell S8786 (super-linear) S5852 (vulnerability) is narrowed to only report exponential backtracking. New rule S8786 (code-smell) covers the remaining super-linear cases (polynomial, quadratic) that are performance concerns but not vulnerabilities.
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 2 issue(s) found across 2 file(s):
Analyzed by SonarQube Agentic Analysis in 8.1 s |
| <li>Replace <code>.</code> with negated character classes to exclude separators where applicable (e.g., <code><strong></strong></code><strong> | ||
| instead of <code>.</code></strong> before <code>,</code>).</li> | ||
| <li>Use bounded quantifiers such as <code>{1,5}</code> to limit repetitions.</li> | ||
| <li>Restructure alternations and quantifiers to eliminate ambiguity — avoid patterns where multiple alternatives can match the same character.</li> | ||
| <li>Use possessive quantifiers (<code>+`, `*</code>, <code>?+</code>) or atomic grouping to prevent the regex engine from keeping backtracking | ||
| positions.</li> |
There was a problem hiding this comment.
💡 Quality: S8786.html has broken markup in fix recommendations
In S8786.html the 'How to fix it' list contains malformed HTML. The negated-character-class example renders as an empty <code></code> tag instead of showing something like [^,] (line ~11), and the possessive-quantifier bullet renders literal backticks: <code>+, *</code>, <code>?+</code> instead of ++, *+, ?+ (line ~15). These render as confusing/empty snippets in the rule description shown to users.
Fix:
<li>Replace <code>.</code> with negated character classes to exclude separators where applicable (e.g.,
<code>[^,]</code> instead of <code>.</code> before <code>,</code>).</li>
<li>Use bounded quantifiers such as <code>{1,5}</code> to limit repetitions.</li>
<li>Restructure alternations and quantifiers to eliminate ambiguity.</li>
<li>Use possessive quantifiers (<code>++</code>, <code>*+</code>, <code>?+</code>) or atomic grouping to prevent the
regex engine from keeping backtracking positions.</li>
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Backreferences disable the Java 9 loop optimization, so QUADRATIC_WHEN_OPTIMIZED and LINEAR_WHEN_OPTIMIZED with backrefs remain exponential and must stay in S5852. S8786 no longer reports LINEAR_WHEN_OPTIMIZED at all (either linear/safe or exponential/S5852).
Code Review 👍 Approved with suggestions 1 resolved / 2 findingsSplits regex backtracking logic by introducing S8786 for super-linear cases and restricting S5852 to exponential complexity. Correct the broken markup in the S8786 documentation to ensure proper rendering of fix recommendations. 💡 Quality: S8786.html has broken markup in fix recommendations📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S8786.html:11-16 In S8786.html the 'How to fix it' list contains malformed HTML. The negated-character-class example renders as an empty Fix✅ 1 resolved✅ Security: Exponential backref regexes downgraded from S5852 to S8786 on Java 9+
🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
Summary
AbstractRedosCheckbase class