Monday, April 27, 2026

Security Vulnerability - Regular Expression Denial of Service (ReDoS)

NVD - CVE-2025-69873

 1. Backtracking (in the context of regular expressions and algorithms) is a trial‑and‑error process where the engine tries one possible path, and if that path fails, it goes back (“backtracks”) and tries another.

Think of backtracking like this:

“Try option A.
If it doesn’t work, rewind and try option B.
If that doesn’t work, rewind further and try option C…”

This is fine when there are only a few options.
It becomes dangerous when the number of options grows exponentially.


What is catastrophic backtracking?

Catastrophic backtracking happens when:

  • A regex has nested repetition or ambiguity
  • The engine must try an enormous number of paths
  • Matching time becomes extremely slow

Example :

^(a+)+$


Why it’s bad:

  • a+ already repeats
  • Wrapping it in ()+ creates nested repetition
  • The engine keeps retrying the same matches in different groupings

Just adding one more character to the input can double execution time.


What is ReDoS

A ReDoS vulnerability stands for Regular Expression Denial of Service. It is a type of Denial‑of‑Service (DoS) attack that exploits how some regular expressions are evaluated.

ReDoS happens when a specially crafted input causes a regular expression to take an extremely long time to evaluate, consuming CPU and making an application unresponsive.


Why backtracking causes ReDoS

Backtracking itself is normal.
It becomes a vulnerability when attackers can control the input.

Attack flow:

  1. Attacker sends specially crafted input
  2. Regex engine enters massive backtracking
  3. CPU usage spikes
  4. Application becomes unresponsive

In Node.js or single‑threaded environments:

  • One slow regex = entire server blocked

What makes it a vulnerability?

ReDoS becomes a security vulnerability when:

  1. A regex is evaluated on untrusted input
  2. The regex or the input can be influenced by an attacker
  3. The regex runs on a shared or single-threaded resource (e.g. Node.js event loop)

An attacker can then:

  • Send a single request
  • Tie up CPU
  • Block all other users

Getting access token from Microsoft using Powershell

 


$tenantId   = "<your-tenant-id>"

$clientId   = "<yourclient-id>"

$client_secret= "<client-secret>"

$scope      = "api://<your-client-id>/.default"

$grant_type = "client_credentials"


$tokenUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"


$body = @{

    client_id      = "$clientId"

    client_secret  = "$client_secret"

    scope          =  "$scope"

    grant_type     = "client_credentials"

}


$graphToken = Invoke-RestMethod `

    -Method POST `

    -Uri $tokenUrl `

    -ContentType "application/x-www-form-urlencoded" `

    -Body $body



$token =  $graphToken.access_token