CVE-2021-32618
JSON

3.1low

Open Redirect Vulnerability

Severity
3.1low CVSS:3.1 by GitHub_M
Exploit likelihood
2.84% (higher than 87% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-6qmf-fj6m-686cPYSEC-2021-123

Description

The Python "Flask-Security-Too" package is used for adding security features to your Flask application. It is an is an independently maintained version of Flask-Security based on the 3.0.0 version of Flask-Security. All versions of Flask-Security-Too allow redirects after many successful views (e.g. /login) by honoring the ?next query param. There is code in FS to validate that the url specified in the next parameter is either relative OR has the same netloc (network location) as the requesting URL. This check utilizes Pythons urlsplit library. However many browsers are very lenient on the kind of URL they accept and 'fill in the blanks' when presented with a possibly incomplete URL. As a concrete example - setting http://login?next=\\\github.com will pass FS's relative URL check however many browsers will gladly convert this to http://github.com. Thus an attacker could send such a link to an unwitting user, using a legitimate site and have it redirect to whatever site they want. This is considered a low severity due to the fact that if Werkzeug is used (which is very common with Flask applications) as the WSGI layer, it by default ALWAYS ensures that the Location header is absolute - thus making this attack vector mute. It is possible for application writers to modify this default behavior by setting the 'autocorrect_location_header=False`.

Affected

Product or packageVersionsReported by
Flask-Middleware flask-security<= 4.0.1CVE List
flask-security-too (PyPI)before 4.1.0GitHub Advisory Database, PyPA Advisory Database
flask-security_project flask-securityNot specifiedNVD

All scores

GitHub_M3.1low CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:L/A:N
GitHub3.1low CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:L/A:N
GitHublow CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:A/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N
NVD6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
NVD5.8medium CVSS:2.0AV:N/AC:M/Au:N/C:P/I:P/A:N

Classification

What each source says

CVE List

The Python "Flask-Security-Too" package is used for adding security features to your Flask application. It is an is an independently maintained version of Flask-Security based on the 3.0.0 version of Flask-Security. All versions of Flask-Security-Too allow redirects after many successful views (e.g. /login) by honoring the ?next query param. There is code in FS to validate that the url specified in the next parameter is either relative OR has the same netloc (network location) as the requesting URL. This check utilizes Pythons urlsplit library. However many browsers are very lenient on the kind of URL they accept and 'fill in the blanks' when presented with a possibly incomplete URL. As a concrete example - setting http://login?next=\\\github.com will pass FS's relative URL check however many browsers will gladly convert this to http://github.com. Thus an attacker could send such a link to an unwitting user, using a legitimate site and have it redirect to whatever site they want. This is considered a low severity due to the fact that if Werkzeug is used (which is very common with Flask applications) as the WSGI layer, it by default ALWAYS ensures that the Location header is absolute - thus making this attack vector mute. It is possible for application writers to modify this default behavior by setting the 'autocorrect_location_header=False`.

GitHub Advisory Database
Impact

Flask-Security allows redirects after many successful views (e.g. /login) by honoring the ?next query param. There is code in FS to validate that the url specified in the next parameter is either relative OR has the same netloc (network location) as the requesting URL.

This check utilizes Pythons urlsplit library. However many browsers are very lenient on the kind of URL they accept and 'fill in the blanks' when presented with a possibly incomplete URL. As a concrete example - setting http://login?next=\\\github.com will pass FS's relative URL check however many browsers will gladly convert this to http://github.com. Thus an attacker could send such a link to an unwitting user, using a legitimate site and have it redirect to whatever site they want.

This is considered a low severity due to the fact that if Werkzeug by default ALWAYS ensures that the Location header is absolute - thus making this attack vector mute. It is possible for application writers to modify this default behavior by setting the 'autocorrect_location_header=False` which would then open up their application to this attack.

Patches

No patches as this time

Workarounds

If using Werkzeug, make sure to use the default Location header setting. If you can't - then use@app.after_request and write your own validation of the Location header if it is set.

References

No.

For more information

If you have any questions or comments about this advisory follow: https://github.com/Flask-Middleware/flask-security/issues/486

Thanks to Claroty (2021-0141) and @snoopysecurity for providing details and proof of concept.

NVD (es)

El paquete Python "Flask-Security-Too" es usado para añadir características de seguridad a su aplicación Flask. Es una versión mantenida independientemente de Flask-Security basada en la versión 3.0.0 de Flask-Security. Todas las versiones de Flask-Security-Too permiten redirecciones después de muchas visualizaciones con éxito (por ejemplo, /login) al honrar al parámetro de consulta ?next. Se presenta un código en FS para comprobar que la url especificada en el siguiente parámetro next es relativa O presenta la misma netloc (ubicación de red) que la URL pedida. Esta comprobación usa la biblioteca Python urlsplit. Sin embargo, muchos navegadores son muy indulgentes con el tipo de URL que aceptan y "fill in the blanks" cuando se les presenta una URL posiblemente incompleta. Como ejemplo concreto - ajustando http://login?next=\\github.com pasará la comprobación de URLs relativas de FS sin embargo muchos navegadores convertirán gustosamente esto en http://github.com. Por lo tanto, un atacante podría enviar dicho enlace a un usuario involuntario, usando un sitio legítimo y hacer que se redirija a cualquier sitio que desee. Esto se considera de baja gravedad debido al hecho de que si es usado Werkzeug (que es muy común con las aplicaciones Flask) como la capa WSGI, por defecto SIEMPRE asegura que la cabecera Location es absoluta - haciendo así este vector de ataque mudo. Es posible para los escritores de aplicaciones modificar este comportamiento por defecto estableciendo el parámetro "autocorrect_location_header=False"

PyPA Advisory Database

The Python "Flask-Security-Too" package is used for adding security features to your Flask application. It is an is an independently maintained version of Flask-Security based on the 3.0.0 version of Flask-Security. All versions of Flask-Security-Too allow redirects after many successful views (e.g. /login) by honoring the ?next query param. There is code in FS to validate that the url specified in the next parameter is either relative OR has the same netloc (network location) as the requesting URL. This check utilizes Pythons urlsplit library. However many browsers are very lenient on the kind of URL they accept and 'fill in the blanks' when presented with a possibly incomplete URL. As a concrete example - setting http://login?next=\\\github.com will pass FS's relative URL check however many browsers will gladly convert this to http://github.com. Thus an attacker could send such a link to an unwitting user, using a legitimate site and have it redirect to whatever site they want. This is considered a low severity due to the fact that if Werkzeug is used (which is very common with Flask applications) as the WSGI layer, it by default ALWAYS ensures that the Location header is absolute - thus making this attack vector mute. It is possible for application writers to modify this default behavior by setting the autocorrect_location_header=False.

References

https://github.com/Flask-Middleware/flask-security/security/advisories/GHSA-6qmf-fj6m-686cadvisory, third-party-advisory
https://github.com/Flask-Middleware/flask-security/issues/486report, third-party-advisory
https://nvd.nist.gov/vuln/detail/CVE-2021-32618advisory
https://github.com/Flask-Middleware/flask-security/commit/e39bb04615050448c1b8ba4caa7dacc0edd3e405web
https://github.com/Flask-Middleware/flask-securitypackage
https://github.com/pypa/advisory-database/tree/main/vulns/flask-security-too/PYSEC-2021-123.yamlweb
https://web.archive.org/web/20210517211717/https://github.com/Flask-Middleware/flask-security/issues/486web
https://web.archive.org/web/20211207121851/https://github.com/Flask-Middleware/flask-security/security/advisories/GHSA-6qmf-fj6m-686cweb
https://web.archive.org/web/20220410062740/https://github.com/Flask-Middleware/flask-security/pull/489web

Sources

SourceRecordLicence
CVE ListCVE-2021-32618 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-6qmf-fj6m-686c changed 2024-09-20CC-BY-4.0
NVDCVE-2021-32618 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-123 changed 2023-11-08CC-BY-4.0