Skip to main content

Add your description here

Project description

ReDoS Linter

A Python linter that detects Regular Expression Denial of Service (ReDoS) vulnerabilities in your code. ReDoS attacks occur when malicious input causes exponential backtracking in regular expressions, leading to denial of service.

Features

  • Scans Python files for regular expressions
  • Detects vulnerable regex patterns using the recheck engine
  • Provides detailed attack vectors when vulnerabilities are found
  • Supports both file and directory scanning
  • Clean, colored output for better readability

Installation

pip install redos-linter

Usage

Command Line

Check specific files or directories:

# Check a single file
redos-linter myfile.py

# Check multiple files
redos-linter file1.py file2.py

# Check a directory (recursively scans all .py files)
redos-linter src/

# Check multiple directories
redos-linter src/ tests/

Python Module

You can also run it as a Python module:

python -m redos_linter src/

Output

The linter provides clear output indicating:

  • Safe: No ReDoS vulnerabilities detected
  • Vulnerable: ReDoS vulnerability found with attack vector details

When vulnerabilities are detected, the output includes:

  • The vulnerable regular expression
  • File location (line and column)
  • Source code context
  • Attack string that can trigger the ReDoS
  • Pump strings for the attack

Examples of Vulnerable Patterns

import re

# Exponential backtracking due to nested quantifiers
vulnerable_1 = re.compile(r"^(a+)+$")

# Exponential backtracking due to overlapping quantifiers
vulnerable_2 = re.compile(r"(a|aa)+")

# Complex nested pattern
vulnerable_3 = re.compile(r"([a-z]+)+$")

# Real-world example
vulnerable_4 = re.compile(r"^(name|email|phone),([a-zA-Z0-9_]+,)*([a-zA-Z0-9_]+)$")

Examples of Safe Patterns

import re

# Simple safe regex
safe_1 = re.compile(r"^[a-zA-Z0-9_]+$")

# Email pattern (properly structured)
safe_2 = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")

# Non-overlapping alternation
safe_3 = re.compile(r"^(cat|dog)$")

Development

Install in development mode:

# Clone the repository
git clone <repository-url>
cd redos-linter

# Install in development mode
uv sync

# Run tests
uv run pytest

# Run linter on test file
uv run python -m redos_linter test.py

How It Works

  1. AST Analysis: Extracts all regular expression literals from Python source code using AST parsing
  2. ReDoS Detection: Uses the recheck engine to analyze each regex for potential exponential backtracking
  3. Attack Generation: When vulnerabilities are found, generates specific attack strings that demonstrate the issue
  4. Reporting: Provides clear, actionable output with source context and attack vectors

Requirements

  • Python 3.10+
  • Deno runtime (automatically managed via the deno Python package)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redos_linter-0.1.2.tar.gz (749.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redos_linter-0.1.2-py3-none-any.whl (749.6 kB view details)

Uploaded Python 3

File details

Details for the file redos_linter-0.1.2.tar.gz.

File metadata

  • Download URL: redos_linter-0.1.2.tar.gz
  • Upload date:
  • Size: 749.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for redos_linter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2d5efe8628da3e0077c1d6bbe1dabb3fcb397297b466c26d4d6077d93a0ce731
MD5 07801198d21f40553952117e783e1699
BLAKE2b-256 1f937e66d6da14e51bddfefb0d9810585d4d0ea81abc1cbc070835df72905ea9

See more details on using hashes here.

File details

Details for the file redos_linter-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: redos_linter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 749.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for redos_linter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cfc44f732dd9735cd40f53cd193e3e788e006868db6c6af97d0a5e87ebf62e8
MD5 c20df9089c4e803bef8bc3b665f6b278
BLAKE2b-256 609e9d6ff53aec46e460673f79c114f9d89120479c1e877df3430855f54349bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page