Categories: Cyber Security News

Ruby on Rails Vulnerability Let Bypass CSRF Protections

Security experts revealed a critical vulnerability in Ruby on Rails that allows attackers to bypass Cross-Site Request Forgery (CSRF) protections.

The flaw, disclosed on April 26, 2025, affects all current versions of the popular web framework and all versions since the 2022/2023 supposed “fix” for similar issues.

The vulnerability emerges from a fundamental flaw in Rails’ CSRF token implementation. The framework generates these security tokens using a random “one time pad” (OTP) XORed with a “raw token.”

However, in a critical oversight, Rails packages both the OTP and the XORed token together through simple concatenation, creating what it calls a “masked token.”

This implementation error means attackers can easily decode CSRF tokens and generate new valid ones, completely circumventing the protection mechanism designed to prevent cross-site attacks.

Since the cryptographic key (the OTP) is sent alongside the encrypted data, the security measure is fundamentally compromised.

Seclists analysts and researchers noted that this vulnerability represents a significant security risk for thousands of websites built using Rails.

The flaw effectively nullifies a critical security layer that many developers rely on to protect their applications from malicious actors.

The vulnerability was first reported by security researcher Daniel Owens, who provided comprehensive evidence of the flaw.

His disclosure indicates this is essentially the same vulnerability that Rails developers believed they had fixed in updates released in 2022/2023.

Technical Analysis of the Vulnerability

The technical root of the vulnerability lies in the mask_token method within the Rails codebase. This method is responsible for creating the “masked” version of the authenticity token that’s meant to vary with each request to mitigate SSL attacks like BREACH.

The problematic implementation can be seen in the following code snippet:-

def mask_token(raw_token)
  one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH)
  encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token)
  masked_token = one_time_pad + encrypted_csrf_token
  encode_csrf_token(masked_token)
end

As evident in this code, Rails generates a random one-time pad and uses it to encrypt the token through an XOR operation.

It then simply concatenates the encryption key with the encrypted data before sending it to users, violating a fundamental principle of cryptographic security.

Owens demonstrated the vulnerability with JavaScript code that easily extracts the encryption key and forges new valid tokens:-

function getCsrfToken(otp, raw_token) {
  var masked_token = new Uint8Array(raw_token.length);
  for(var i = 0; i  String.fromCharCode(b)).join('')).replace(/=+$/, '');
}

This exploit allows attackers to craft malicious requests that bypass CSRF protection, potentially leading to unauthorized actions performed on behalf of authenticated users on vulnerable Rails applications.

Malware Trends Report Based on 15000 SOC Teams Incidents, Q1 2025 out!-> Get Your Free Copy

The post Ruby on Rails Vulnerability Let Bypass CSRF Protections appeared first on Cyber Security News.

rssfeeds-admin

Recent Posts

At last, there’s a Jan. 6 memorial plaque in the US Capitol. But just try finding it.

A plaque commemorating those who protected the U.S. Capitol during the Jan. 6, 2021, insurrection…

7 minutes ago

How to double your blood donation at one visit (and get a smaller needle)

Efficiency experts would love to be able to double their work output. Blood donation centers…

17 minutes ago

With 1,309 potholes fixed so far, this is a horrible year for Concord streets — just like every other year

When it comes to potholes, there’s a bit of wisdom from Jim Major, Concord’s former,…

17 minutes ago

Sunshine Week: Concord’s middle school and the difference between available and accessible public records

At $155 million, a new middle school in Concord, with construction set to begin next…

17 minutes ago

DC Reverses One of Its Most Controversial Plot Twists, as [Spoiler] Returns

Warning: this article contains major spoilers for Superman Unlimited #11!DC Comics has made its fair…

33 minutes ago

This website uses cookies.