Skip to content
CORS Write-up Intermediate

Finding Vulnerabilities On Flask Cors Library

The flask-cors library had four flaws in how it matched request paths to CORS rules: it enabled private network access by default, mishandled '+' in paths, sorted regex rules incorrectly, and matched paths case-insensitively. An attacker could exploit these to make cross-origin requests to endpoints that should only be accessible from trusted origins, potentially reading sensitive data.

Brandon Roldan Follow

Published on infosecwriteups.com

Last few months, i decided to do some source code review, so i went to huntr.dev to see some targets that offer small bounties, and i decided to focus on flask-cors. Throughout my engagement, i discovered a total of 4 vulnerabilities, 3 of which is about improper matching of the urls for applying the cors rules.

Brandon Roldan, on infosecwriteups.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 multiple mistakes in path matching and default settings: using unquote_plus on the path, sorting regexes by length instead of specificity, case-insensitive matching, and enabling private network access by default.

Impact

An attacker could read sensitive data from endpoints that were meant to be restricted to specific origins, by exploiting the misconfigured CORS rules.

What the attacker needed

Victim visits a malicious site; flask-cors used with certain configurations

The fix

The vulnerabilities were fixed in later versions of flask-cors (the report does not specify the exact fix, but implies they were addressed).

How it was found

  1. Set up a Flask app with flask-cors and define CORS rules where one rule allows all origins and another restricts a specific path to a trusted origin.
  2. Send a request to the restricted path with an Origin header from an untrusted domain.
  3. Observe that the response includes Access-Control-Allow-Origin for the untrusted origin, allowing cross-origin access.

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.

CORS is a browser security feature that controls which websites can read responses from another site. If a site's CORS rules are too loose, a malicious website could read private data from another site. This report found several bugs in a Python library that helps set CORS rules, which could let attackers bypass intended restrictions.

What is CORS?

A permissive cross-origin policy lets another site read responses with the user's credentials.

More by Brandon Roldan

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

CORS misconfiguration

The lesson behind this report.

A permissive cross-origin policy lets another site read responses with the user's credentials.