Kingdom: Security Features
Software security is not security software. Here we're concerned with topics like authentication, access control, confidentiality, cryptography, and privilege management.
Django Bad Practices: Overly Broad Host Header Verification
Abstract
Not validating the
Host
header can allow an attacker to send a fake Host
value that can be used for Cross-Site Request Forgery, cache poisoning attacks, and poisoning links in emails.Explanation
The Django applications settings specifies "
Example 1: An application offers a reset password feature where users can submit some kind of unique value to identify themselves (eg: email address) and then a password reset email will be sent with a link to a page to set up a new password. The link sent to the user can be constructed using the
An attacker may try to reset a victim's password by submitting the victim's email and a fake
*
" as an entry in the ALLOWED_HOSTS
setting. This setting is used by django.http.HttpRequest.get_host()
to validate the Host
header. A value of "*
" will allow any host in the Host
header. An attacker may use this in cache poisoning attacks or for poisoning links in emails.Example 1: An application offers a reset password feature where users can submit some kind of unique value to identify themselves (eg: email address) and then a password reset email will be sent with a link to a page to set up a new password. The link sent to the user can be constructed using the
Host
value to reference the site that serves the reset password feature in order to avoid hardcoded URLs. For example:
...
def reset_password(request):
url = "http://%s/new_password/?token=%s" % (request.get_host(), generate_token())
send_email(reset_link=url)
redirect("home")
...
An attacker may try to reset a victim's password by submitting the victim's email and a fake
Host
header value pointing to a server he controls. The victim will receive an email with a link to the reset password system and if he decides to visit the link, she will be visiting the attacker-controlled site which will serve a fake form to collect the victim's credentials.References
[1] Django Foundation Host header validation
[2] Django Foundation ALLOWED_HOSTS
[3] Standards Mapping - General Data Protection Regulation (GDPR) Access Violation
[4] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective C.3.1 - Web Software Attack Mitigation
[5] Standards Mapping - Web Application Security Consortium Version 2.00 Application Misconfiguration (WASC-15)
desc.structural.python.django_bad_practices_overly_broad_host_header_verification