Reports regular expressions with exponential or polynomial backtracking.
✅ This rule is included in the ts logical and logicalStrict presets.
Reports regular expressions that can cause exponential or polynomial backtracking.
These patterns can be exploited to cause Regular Expression Denial of Service (ReDoS) attacks, where a malicious input string causes the regex engine to take an extremely long time to process.
When a quantifier can reach itself through a parent quantifier, it can cause exponential backtracking.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8F(?1/sp><:asp ansty="le--0:#7FDBCA;--1:#096E">7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2+sp ansty="le--0:#D9F5DD;--1:#1111">12+sp><1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d>AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#5CA7E4;--1:#3A68">8Fb(?1/sp><:asp ansty="le--0:#7FDBCA;--1:#096E">7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">688F(111/>6?:a)>1<111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><)+/>)+/><;di vdivclass="Nameexpressive-">44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#5CA7E4;--1:#3A">68111/><8Fba spans="tyle--0:#7FDBCA;--1:#09">68Fba>6<88Fb spans="tyle--0:#D9F5DD;--1:#11">188Fb><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><+b/>+b/>;di>
When two quantifiers can exchange characters, it causes polynomial backtracking.
AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#C792EA;--1:#8844">AE1/sp><\bsp ansty="le--0:#5CA7E4;--1:#3A68">8\bsp>7<2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>7<2+sp ansty="le--0:#C792EA;--1:#8844">A2+sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d>AEconsB0patteAE< =sp ansty="le--0:#5CA7E4;--1:#3A68">8 =sp>1<1/sp ansty="le--0:#C792EA;--1:#8844">AE1/sp><\bsp ansty="le--0:#82AAFF;--1:#3B61">B0\bsp><\wsp ansty="le--0:#7FDBCA;--1:#096E">7\wsp><2+sp ansty="le--0:#5CA7E4;--1:#3A68">82+sp>B0<\wsp ansty="le--0:#7FDBCA;--1:#096E">7\wsp><2+sp ansty="le--0:#C792EA;--1:#8844">A2+sp>1<1/sp ansty="le--0:#D6DEEB;--1:#403F">51/sp><3;d ivclassNa="meco">;d>/;d>3;d> 44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#C792EA;--1:#88">44111/>6<88Fa spans="tyle--0:#7FDBCA;--1:#09">688Fa>4<4AE$ spans="tyle--0:#D9F5DD;--1:#11">14AE$><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/><+$/>+$/><;di vdivclass="Nameexpressive-">44AEco61B0pat446<88F spans="tyle--0:#D9F5DD;--1:#11">188F ><111/ spans="tyle--0:#C792EA;--1:#88">44111/>6166<88Fa spans="tyle--0:#C792EA;--1:#88">488Fa><4AE$ spans="tyle--0:#D9F5DD;--1:#11">14AE$><111/ spans="tyle--0:#D6DEEB;--1:#40">3111/>;di>
The rule also applies to patterns created with the RegExp constructor.
AEconsB0patteAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72n= sp>AB0RegE5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4D(?:a+1"sp><)+sp ansty="le--0:#D9F5DD;--1:#1111">1)+sp><1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0pat44A6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#82AAFF;--1:#3B">61B0Re4AE >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D(?111"><:a)+ spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name"><+")>+")>53)>
This rule is not configurable.
If you are confident that your regular expressions will only be used with trusted input that cannot be manipulated by attackers, you might consider disabling this rule.