Skip to content

GHSA-mhwm-jh88-3gjf CVE-2025-27220

CGI has Regular Expression Denial of Service (ReDoS) potential in Util#escapeElement

High RubyGems
Severity
0.0 / 10
High · CVSS 4.0
Exploit chance (EPSS)
0.76%
Chance of exploitation in the next 30 days. Higher than 55.29% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-1333 Inefficient Regular Expression Complexity
Fix
0.3.5.1
Upgrade cgi to this version or later

Description

There is a possibility for Regular expression Denial of Service (ReDoS) by in the cgi gem. This vulnerability has been assigned the CVE identifier CVE-2025-27220. We recommend upgrading the cgi gem.

Details

The regular expression used in CGI::Util#escapeElement is vulnerable to ReDoS. The crafted input could lead to a high CPU consumption.

This vulnerability only affects Ruby 3.1 and 3.2. If you are using these versions, please update CGI gem to version 0.3.5.1, 0.3.7, 0.4.2 or later.

Affected versions

cgi gem versions <= 0.3.5, 0.3.6, 0.4.0 and 0.4.1.

Credits

Thanks to svalkanov for discovering this issue. Also thanks to nobu for fixing this vulnerability.

Affected versions

RubyGems

PackageVulnerableFixed in
cgi
< 0.3.5.1
0.3.5.1
cgi
>= 0.3.6, < 0.3.7
0.3.7
cgi
>= 0.4.0, < 0.4.2
0.4.2

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

cgi RubyGems → 0.3.5.1

bundler
bundle update cgi # Gemfile: gem "cgi", ">= 0.3.5.1"

Severity breakdown

CVSS 4.0 0.0

CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N

Attack vector
Network
Attack complexity
High
Attack requirements
Present
Privileges required
None
User interaction
None
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
Low
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None

CVSS 3.1 4.0

CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:N/I:N/A:L

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
None
Integrity
None
Availability
Low

Weakness

CWE-1333: Inefficient Regular Expression Complexity

The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.

How to prevent it
  • Architecture and Design: Use regular expressions that do not support backtracking, e.g. by removing nested quantifiers.
  • System Configuration: Set backtracking limits in the configuration of the regular expression implementation, such as PHP's pcre.backtrack_limit. Also consider limits on execution time for the process.
  • Implementation: Do not use regular expressions with untrusted input. If regular expressions must be used, avoid using backtracking in the expression.
  • Implementation: Limit the length of the input that the regular expression will process.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-gh9q-2xrm-x6qv
CGI has Denial of Service (DoS) potential in Cookie.parse
High Also affects cgi
GHSA-vc47-6rqg-c7f5
HTTP response splitting in CGI
High Also affects cgi
GHSA-4vf4-qmvg-mh7h
Cookie Prefix Spoofing in CGI::Cookie.parse
High Also affects cgi
GHSA-5cqm-crxm-6qpv
Buffer overrun in CGI.escape_html
Critical Also affects cgi
GHSA-7wch-p9px-956x
Forge: Regular expression denial of service in PEM decoding (pem.decode)
High Same weakness, CWE-1333
GHSA-xcq7-p3pf-p88h
OpenTelemetry Python: Unbounded tracestate parsing in opentelemetry-api
Medium Same weakness, CWE-1333
GHSA-xgh8-jp6q-p5x8
Pillow: ReDoS in XbmImagePlugin: 512-byte file stalls Image.open() for minutes
High Same weakness, CWE-1333
GHSA-rxp7-6hxx-x8q5
ip-address: Address6 matches a zone identifier in quadratic time ahead of its length limit, allowing a single long string to stall the process
Medium Same weakness, CWE-1333
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor