Skip to content
Info disclosure Write-up Intermediate

CVE-2024-53991 - Discourse Backup Disclosure: Rails send_file Quirk

Discourse's default Nginx configuration protects backup files with the internal directive, but Rails' send_file method can be tricked via request headers to serve those files. An attacker who knows or guesses a backup filename could download the entire database backup.

httpvoid.com

Published on httpvoid.com

Note - This is cross post from our work at Projectdiscovery Blog

The author, on httpvoid.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Rack::Sendfile middleware trusts client-supplied X-Sendfile-Type and X-Accel-Mapping headers to construct the X-Accel-Redirect path, allowing an attacker to map an arbitrary file path to an internal Nginx location.

Impact

An attacker could download sensitive database backups, leading to full data disclosure, but only if they can guess or brute-force the backup filename.

What the attacker needed

Discourse with local file storage for backups; Attacker can guess or brute-force backup filename; No authentication required

The fix

The issue was fixed in Discourse; users should upgrade, or as a workaround disable backups and delete existing ones, or move backups to S3.

How it was found

  1. Identify a Discourse instance using local file storage for backups.
  2. Determine the backup filename pattern: site name, date, time, and migration stamp.
  3. Send a request to an unauthenticated endpoint that uses send_file, such as a stylesheet path, with headers X-Sendfile-Type: X-Accel-Redirect and X-Accel-Mapping pointing to the backup file.
  4. Nginx internally redirects to the backup file and serves it to the attacker.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A web server can be told to serve a file from a protected folder only if the request comes from the application itself, not directly from a user. The application (Discourse) uses a feature that lets the web server handle file downloads, but it trusts certain request headers to decide where to map the file. By sending special headers, an attacker can make the application tell the web server to serve a backup file that was supposed to be private.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.