VAITP Dataset

← Back to the dataset

CVE-2021-23401

Flask-User URL validation bypass via backslashes, exploitable without 'autocorrect_location_header'

  • CVSS 6.1
  • CWE-601 URL Redirection to Untrusted Site ('Open Redirect')
  • Configuration Issues
  • Remote

This affects all versions of package Flask-User. When using the make_safe_url function, it is possible to bypass URL validation and redirect a user to an arbitrary URL by providing multiple back slashes such as /////evil.com/path or \\\evil.com/path. This vulnerability is only exploitable if an alternative WSGI server other than Werkzeug is used, or the default behaviour of Werkzeug is modified using 'autocorrect_location_header=False.

CVSS base score
6.1
Published
2021-07-05
OWASP
A10 Server-Side Request Forgery (SSRF)
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Configuration Issues
Subcategory
Open Redirects
Accessibility scope
Remote
Impact
Unauthorized Access
Affected component
Flask-User
Fixed by upgrading
Yes

Solution

Update Flask-User to the latest version.

Vulnerable code sample

from flask import Flask, redirect, request

app = Flask(__name__)

def make_safe_url(url):
    # Vulnerable URL validation that allows multiple slashes
    return url  # No validation, allows arbitrary URLs

@app.route('/redirect')
def unsafe_redirect():
    target_url = request.args.get('url')
    unsafe_url = make_safe_url(target_url)
    return redirect(unsafe_url)

if __name__ == '__main__':
    app.run()

Patched code sample

from flask import Flask, redirect, request, abort
import re

app = Flask(__name__)

def make_safe_url(url):
    # Validate the URL to prevent redirects to arbitrary locations
    # This regex allows only specific schemes (http, https) and disallows multiple slashes
    if re.match(r'^(http|https)://[^/\\]+(/[^\\]*)?$', url):
        return url
    else:
        abort(400)  # Bad Request if the URL is invalid

@app.route('/redirect')
def safe_redirect():
    target_url = request.args.get('url')
    safe_url = make_safe_url(target_url)
    return redirect(safe_url)

if __name__ == '__main__':
    app.run()

Cite this entry

@misc{vaitp:cve202123401,
  title        = {{Flask-User URL validation bypass via backslashes, exploitable without 'autocorrect_location_header'}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-23401},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-23401/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.