Vulnerability in Ruby CGI::Cookie.parse

ruby Updated 02 Oct 2025

Summary

01/01/2022
N/A
Yes i
High
7.5

CVE-2021-41819: CGI::Cookie.parse in Ruby through 2.6.8 mishandles security prefixes in cookie names. This also affects the CGI gem through 0.3.0 for Ruby. Affects ruby across 2 version ranges.

< 2.7.5-r0 >= 647ee6f091eafcce70ffb75ddf7e121e192ab217, < f69aeb83146be640995753667fdd6c6f157527f5

Fixed in 2.7.5-r0. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

Ruby is a popular programming language known for its simplicity and flexibility. It is widely used for web development, scripting, and automation tasks. One of the key components in Ruby is the CGI module, which provides functionality for handling Common Gateway Interface (CGI) requests and responses. The CGI::Cookie.parse method is responsible for parsing cookies in CGI requests. However, a vulnerability has been discovered in this method that mishandles security prefixes in cookie names. This vulnerability affects Ruby versions up to 2.6.8 and the CGI gem up to 0.3.0.

Vulnerability Detail

The vulnerability in CGI::Cookie.parse allows an attacker to bypass security measures by manipulating cookie names. By including a security prefix in a cookie name, an attacker can deceive the application into treating the cookie as secure when it is not. This can lead to various security issues, such as session hijacking, cross-site scripting (XSS), and privilege escalation. The vulnerability has a CVSS score of 7.5, indicating a high severity level.

How To Fix

Minimum fixed version

2.7.5-r0

This is the first release that contains the fix.

sudo apk add --upgrade ruby

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a workaround, developers can manually validate cookie names and ensure that security prefixes are properly handled. This can be done by implementing custom cookie parsing logic that checks for security prefixes and rejects cookies with invalid or unexpected prefixes. Here is an example of how this can be done in Ruby:

require 'cgi'

def parse_cookies(cookie_string)
  cookies = {}
  cookie_string.split(';').each do |cookie|
    name, value = cookie.split('=', 2)
    if name.start_with?('secure_')
      # Handle secure cookie
      name = name[7..-1]
      # Validate and process the cookie
      ...
    else
      # Handle regular cookie
      # Validate and process the cookie
      ...
    end
    cookies[name] = value
  end
  cookies
end

This code snippet demonstrates a basic approach to manually parsing and validating cookies, taking into account the presence of security prefixes.

Conclusion

The vulnerability in Ruby's CGI::Cookie.parse method can lead to security bypass and potential attacks. It is crucial to update Ruby and the CGI gem to the recommended versions to mitigate the risk. Developers can also implement custom cookie parsing logic as a temporary workaround. For further support and assistance in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for ruby →

Share this vulnerability

FAQ

The vulnerability allows an attacker to bypass security measures and potentially perform malicious actions, such as session hijacking or cross-site scripting (XSS). It is important to update Ruby and the CGI gem to prevent exploitation.

The vulnerability affects Ruby versions up to 2.6.8. It is recommended to update to version 2.7.5-r0 or later.

At the time of this report, there are no known public exploits targeting this specific vulnerability. However, it is crucial to apply the recommended updates to mitigate the risk.

Yes, this vulnerability can be exploited remotely. An attacker can send a specially crafted request containing manipulated cookie names to exploit the vulnerability.

Yes, the CVSS score for this vulnerability is 7.5, indicating a high severity level.

Related vulnerabilities

Recent vulnerabilities recorded for ruby.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

How To Fix

Minimum fixed version

2.7.5-r0

This is the first release that contains the fix.

sudo apk add --upgrade ruby

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback