The SentinelOne Annual Threat Report - A Defenders Guide from the FrontlinesThe SentinelOne Annual Threat ReportGet the Report
Experiencing a Breach?Blog
Get StartedContact Us
SentinelOne
  • Platform
    Platform Overview
    • Singularity Platform
      Welcome to Integrated Enterprise Security
    • AI for Security
      Leading the Way in AI-Powered Security Solutions
    • Securing AI
      Accelerate AI Adoption with Secure AI Tools, Apps, and Agents.
    • How It Works
      The Singularity XDR Difference
    • Singularity Marketplace
      One-Click Integrations to Unlock the Power of XDR
    • Pricing & Packaging
      Comparisons and Guidance at a Glance
    Data & AI
    • Purple AI
      Accelerate SecOps with Generative AI
    • Singularity Hyperautomation
      Easily Automate Security Processes
    • AI-SIEM
      The AI SIEM for the Autonomous SOC
    • Singularity Data Lake
      AI-Powered, Unified Data Lake
    • Singularity Data Lake for Log Analytics
      Seamlessly Ingest Data from On-Prem, Cloud or Hybrid Environments
    Endpoint Security
    • Singularity Endpoint
      Autonomous Prevention, Detection, and Response
    • Singularity XDR
      Native & Open Protection, Detection, and Response
    • Singularity RemoteOps Forensics
      Orchestrate Forensics at Scale
    • Singularity Threat Intelligence
      Comprehensive Adversary Intelligence
    • Singularity Vulnerability Management
      Application & OS Vulnerability Management
    • Singularity Identity
      Identity Threat Detection and Response
    Cloud Security
    • Singularity Cloud Security
      Block Attacks with an AI-Powered CNAPP
    • Singularity Cloud Native Security
      Secure Cloud and Development Resources
    • Singularity Cloud Workload Security
      Real-Time Cloud Workload Protection Platform
    • Singularity Cloud Data Security
      AI-Powered Threat Detection for Cloud Storage
    • Singularity Cloud Security Posture Management
      Detect and Remediate Cloud Misconfigurations
    Securing AI
    • Prompt Security
      Secure AI Tools Across Your Enterprise
  • Why SentinelOne?
    Why SentinelOne?
    • Why SentinelOne?
      Cybersecurity Built for What’s Next
    • Our Customers
      Trusted by the World’s Leading Enterprises
    • Industry Recognition
      Tested and Proven by the Experts
    • About Us
      The Industry Leader in Autonomous Cybersecurity
    Compare SentinelOne
    • Arctic Wolf
    • Broadcom
    • CrowdStrike
    • Cybereason
    • Microsoft
    • Palo Alto Networks
    • Sophos
    • Splunk
    • Trellix
    • Trend Micro
    • Wiz
    Verticals
    • Energy
    • Federal Government
    • Finance
    • Healthcare
    • Higher Education
    • K-12 Education
    • Manufacturing
    • Retail
    • State and Local Government
  • Services
    Managed Services
    • Managed Services Overview
      Wayfinder Threat Detection & Response
    • Threat Hunting
      World-Class Expertise and Threat Intelligence
    • Managed Detection & Response
      24/7/365 Expert MDR Across Your Entire Environment
    • Incident Readiness & Response
      DFIR, Breach Readiness, & Compromise Assessments
    Support, Deployment, & Health
    • Technical Account Management
      Customer Success with Personalized Service
    • SentinelOne GO
      Guided Onboarding & Deployment Advisory
    • SentinelOne University
      Live and On-Demand Training
    • Services Overview
      Comprehensive Solutions for Seamless Security Operations
    • SentinelOne Community
      Community Login
  • Partners
    Our Network
    • MSSP Partners
      Succeed Faster with SentinelOne
    • Singularity Marketplace
      Extend the Power of S1 Technology
    • Cyber Risk Partners
      Enlist Pro Response and Advisory Teams
    • Technology Alliances
      Integrated, Enterprise-Scale Solutions
    • SentinelOne for AWS
      Hosted in AWS Regions Around the World
    • Channel Partners
      Deliver the Right Solutions, Together
    • SentinelOne for Google Cloud
      Unified, Autonomous Security Giving Defenders the Advantage at Global Scale
    • Partner Locator
      Your Go-to Source for Our Top Partners in Your Region
    Partner Portal→
  • Resources
    Resource Center
    • Case Studies
    • Data Sheets
    • eBooks
    • Reports
    • Videos
    • Webinars
    • Whitepapers
    • Events
    View All Resources→
    Blog
    • Feature Spotlight
    • For CISO/CIO
    • From the Front Lines
    • Identity
    • Cloud
    • macOS
    • SentinelOne Blog
    Blog→
    Tech Resources
    • SentinelLABS
    • Ransomware Anthology
    • Cybersecurity 101
  • About
    About SentinelOne
    • About SentinelOne
      The Industry Leader in Cybersecurity
    • Investor Relations
      Financial Information & Events
    • SentinelLABS
      Threat Research for the Modern Threat Hunter
    • Careers
      The Latest Job Opportunities
    • Press & News
      Company Announcements
    • Cybersecurity Blog
      The Latest Cybersecurity Threats, News, & More
    • FAQ
      Get Answers to Our Most Frequently Asked Questions
    • DataSet
      The Live Data Platform
    • S Foundation
      Securing a Safer Future for All
    • S Ventures
      Investing in the Next Generation of Security, Data and AI
  • Pricing
Get StartedContact Us
CVE Vulnerability Database
Vulnerability Database/CVE-2021-27291

CVE-2021-27291: Pygments ReDoS Denial of Service Flaw

CVE-2021-27291 is a ReDoS denial of service vulnerability in Pygments caused by inefficient regular expressions in lexers. Attackers can exploit this to cause system unavailability. This article covers technical details, affected versions, impact, and mitigation strategies.

Published: February 25, 2026

CVE-2021-27291 Overview

CVE-2021-27291 is a Regular Expression Denial of Service (ReDoS) vulnerability affecting Pygments, a popular Python syntax highlighting library used in numerous web applications, documentation tools, and code formatting systems. The vulnerability exists in versions 1.1 through 2.7.3, where multiple lexers contain regular expressions with exponential or cubic worst-case complexity that can be exploited to cause denial of service conditions.

Critical Impact

Attackers can craft malicious input that triggers catastrophic backtracking in vulnerable regular expressions, causing CPU exhaustion and denial of service in applications that process untrusted code for syntax highlighting.

Affected Products

  • Pygments versions 1.1 through 2.7.3
  • Debian Linux 9.0 and 10.0
  • Fedora 32 and 33

Discovery Timeline

  • 2021-03-17 - CVE-2021-27291 published to NVD
  • 2024-11-21 - Last updated in NVD database

Technical Details for CVE-2021-27291

Vulnerability Analysis

The vulnerability stems from the use of inefficient regular expressions within Pygments lexers. Regular expressions that contain certain patterns—such as nested quantifiers or overlapping alternations—can exhibit exponential time complexity when processing carefully crafted input strings. This type of vulnerability, known as ReDoS (Regular Expression Denial of Service), occurs when the regex engine enters a state of catastrophic backtracking.

In Pygments, multiple lexers used to parse various programming languages contain these problematic regex patterns. When an application using Pygments processes malicious input through an affected lexer, the regex engine can consume excessive CPU resources attempting to match the pattern, effectively freezing the application and causing denial of service.

Root Cause

The root cause is the presence of regular expressions with exponential or cubic worst-case complexity in Pygments lexers. These patterns are vulnerable to algorithmic complexity attacks. For example, in pygments/lexers/archetype.py, the original regex [+-]?(\d+)*\.\\d+%? contained a nested quantifier (\d+)* that could cause catastrophic backtracking.

Attack Vector

The attack is network-accessible and requires no authentication or user interaction. An attacker can submit malicious code snippets to any application that uses Pygments for syntax highlighting—such as code paste services, documentation generators, or web forums with code formatting—causing the server to become unresponsive as it processes the malicious input.

The following patch demonstrates the fix applied to address one of the vulnerable regular expressions:

python
             (r'P((\d*(\.\d+)?[YyMmWwDd]){1,3}(T(\d*(\.\d+)?[HhMmSs]){,3})?|'
              r'T(\d*(\.\d+)?[HhMmSs]){,3})', Literal.Date),
             (r'[+-]?(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
-            (r'[+-]?(\d+)*\.\\d+%?', Number.Float),
+            (r'[+-]?\d*\.\d+%?', Number.Float),
             (r'0x[0-9a-fA-F]+', Number.Hex),
             (r'[+-]?\d+%?', Number.Integer),
         ],

Source: GitHub Commit Update

The CHANGES file documents the security fixes:

text
 - Limit recursion with nesting Ruby heredocs (#1638)
 - Fix a few inefficient regexes for guessing lexers
 - Fix the raw token lexer handling of Unicode (#1616)
-- Revert a private API change in the HTML formatter (#1655) -- please note that private APIs remain subject to change!
+- Revert a private API change in the HTML formatter (#1655) -- 
+  please note that private APIs remain subject to change!
 - Add Dracula theme style (#1636)
+- Fix several exponential/cubic-complexity regexes found by
+  Ben Caller/Doyensec (#1675)
 
Thanks to Google's OSS-Fuzz project for finding many of these bugs.
 

Source: GitHub Commit Update

Detection Methods for CVE-2021-27291

Indicators of Compromise

  • Abnormally high CPU utilization on servers running Pygments-based syntax highlighting
  • Application timeouts or unresponsiveness when processing specific code snippets
  • Memory consumption spikes during code parsing operations
  • Increased response latency for code formatting endpoints

Detection Strategies

  • Monitor CPU and memory usage patterns on systems running applications that use Pygments for syntax highlighting
  • Implement application-level request timeout monitoring to detect requests that take unusually long to process
  • Deploy web application firewalls (WAF) with rate limiting to mitigate high-volume attack attempts
  • Use dependency scanning tools to identify vulnerable Pygments versions in your software supply chain

Monitoring Recommendations

  • Set up alerting for CPU utilization exceeding normal thresholds on application servers
  • Monitor application response times and flag significant deviations from baseline performance
  • Track Pygments-related processing times in application logs
  • Implement request timeout enforcement at the application and infrastructure levels

How to Mitigate CVE-2021-27291

Immediate Actions Required

  • Upgrade Pygments to version 2.7.4 or later immediately
  • Audit applications and dependencies for use of vulnerable Pygments versions
  • Implement request timeouts for code highlighting operations as a defense-in-depth measure
  • Consider rate limiting on endpoints that accept code input for syntax highlighting

Patch Information

The vulnerability has been fixed in Pygments version 2.7.4. The fix addresses several exponential and cubic complexity regular expressions identified by Ben Caller of Doyensec. The security patch is available via the GitHub Commit Update. Additional security advisories have been published by Debian Security Advisory DSA-4878 and Debian Security Advisory DSA-4889.

Workarounds

  • Implement strict input length limits for code submitted for syntax highlighting
  • Set aggressive timeouts on code processing operations to prevent resource exhaustion
  • Use process isolation or sandboxing for Pygments processing to contain potential DoS impacts
  • Deploy rate limiting on code formatting endpoints to reduce attack surface
bash
# Upgrade Pygments to the patched version
pip install --upgrade pygments>=2.7.4

# Verify installed version
pip show pygments | grep Version

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

  • Vulnerability Details
  • TypeDOS

  • Vendor/TechPygments

  • SeverityHIGH

  • CVSS Score7.5

  • EPSS Probability2.38%

  • Known ExploitedNo
  • CVSS Vector
  • CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
  • Impact Assessment
  • ConfidentialityLow
  • IntegrityNone
  • AvailabilityHigh
  • CWE References
  • CWE-1333
  • Technical References
  • GitHub Gist PoC

  • Debian LTS Advisory March 2021

  • Debian LTS Advisory May 2021

  • Debian LTS Advisory May 2021

  • Fedora Package Announcement

  • Fedora Package Announcement

  • Debian Security Advisory DSA-4878

  • Debian Security Advisory DSA-4889
  • Vendor Resources
  • GitHub Commit Update
  • Related CVEs
  • CVE-2026-4539: Pygments DOS Vulnerability

  • CVE-2021-20270: Pygments SMLLexer DoS Vulnerability
Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the World’s Most Advanced Cybersecurity Platform

See how our intelligent, autonomous cybersecurity platform can protect your organization now and into the future.

Try SentinelOne
  • Get Started
  • Get a Demo
  • Product Tour
  • Why SentinelOne
  • Pricing & Packaging
  • FAQ
  • Contact
  • Contact Us
  • Customer Support
  • SentinelOne Status
  • Language
  • Platform
  • Singularity Platform
  • Singularity Endpoint
  • Singularity Cloud
  • Singularity AI-SIEM
  • Singularity Identity
  • Singularity Marketplace
  • Purple AI
  • Services
  • Wayfinder TDR
  • SentinelOne GO
  • Technical Account Management
  • Support Services
  • Verticals
  • Energy
  • Federal Government
  • Finance
  • Healthcare
  • Higher Education
  • K-12 Education
  • Manufacturing
  • Retail
  • State and Local Government
  • Cybersecurity for SMB
  • Resources
  • Blog
  • Labs
  • Case Studies
  • Videos
  • Product Tours
  • Events
  • Cybersecurity 101
  • eBooks
  • Webinars
  • Whitepapers
  • Press
  • News
  • Ransomware Anthology
  • Company
  • About Us
  • Our Customers
  • Careers
  • Partners
  • Legal & Compliance
  • Security & Compliance
  • Investor Relations
  • S Foundation
  • S Ventures

©2026 SentinelOne, All Rights Reserved.

Privacy Notice Terms of Use

English