BETA Shoulder jest w wersji beta — Wyniki mogą czasami być błędne. Twoja opinia kształtuje to, co naprawimy w następnej kolejności. Podziel się opinią
🔄

Inefficient Regular Expression Complexity

🛡️ 3 reguł wykrywa to

Inefficient Regular Expression Complexity

The product uses a regular expression with an inefficient, possibly exponential worst-case computational complexity that consumes excessive CPU cycles.

Certain regular expression patterns can take exponential time to evaluate on certain inputs (ReDoS). Attackers can craft inputs that cause the regex engine to consume excessive CPU time, leading to denial of service.

Rozpowszechnienie
Średnia
Pokryto 3 języków
Wplyw
Wysoki
1 reguł o wysokim poziomie
Zapobieganie
Udokumentowane
3 przykładów poprawek
2 Zapobieganie
2 Zapobieganie

Jak naprawić tę podatność

Strategie zapobiegania dla ReDoS oparte na 3 regułach detekcji Shoulder.

Regular Expression Denial of Service MEDIUM

Avoid nested quantifiers in regex; use specific character classes instead

+1 -1 go
- re := regexp.MustCompile("(a+)+b")
+ re := regexp.MustCompile("^[a-z]+b$")
  
Regular Expression Denial of Service (ReDoS) HIGH

Avoid nested quantifiers in regex and validate input length before matching

+6 -2 javascript
- const emailRegex = /^([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}$/;
- if (emailRegex.test(req.body.email)) {
+ const validator = require('validator');
+ 
+ if (req.body.email.length > 254) {
+   return res.status(400).json({ error: 'Input too long' });
+ }
+ if (validator.isEmail(req.body.email)) {
    processEmail(req.body.email);
  }
  
Regular Expression Denial of Service (ReDoS) MEDIUM

Replace nested quantifiers with simple patterns and bounded repetition

+1 -1 python
  import re
  
- email_pattern = re.compile(r'^([a-zA-Z0-9._-]+)+@[a-zA-Z0-9.-]+$')
+ email_pattern = re.compile(r'^[a-zA-Z0-9._-]{1,64}@[a-zA-Z0-9.-]{1,255}$')
  
  def validate_email(email):
      return email_pattern.match(email)
  

Kluczowe praktyki

  • Use exponential time complexity when matching certain inputs
3 Wykrywanie
3 Wykrywanie

Znajdz podatnosci w swoim kodzie

Uzyj Shoulder do skanowania kodu w poszukiwaniu wzorcow Inefficient Regular Expression Complexity. 3 reguly.

terminal
# Scan with Shoulder CLI
npx @shoulderdev/cli trust --cwe=1333

# Or scan entire project
npx @shoulderdev/cli trust .

Reguly Wykrywania (3)

4 Sygnaly Ostrzegawcze
4 Sygnaly Ostrzegawcze

Na co zwracac uwage podczas przegladu kodu

Te wzorce wskazuja na potencjalne podatnosci Inefficient Regular Expression Complexity. Szukaj ich podczas przegladow kodu i audytow bezpieczenstwa.

🟠
potentially catastrophic regular expressions that could lead to ReDoS attacks javascript-regex-dos
🟡
regular expressions with catastrophic backtracking patterns that can cause exponential time complexi python-redos
🔍

Przeskanuj swój kod w poszukiwaniu Inefficient Regular Expression Complexity

Shoulder CLI znajduje podatne wzorce w całym Twoim kodzie.