[valid_referers] Weak entries in valid_referers
What this check looks for
This plugin warns when valid_referers includes:
- the
noneorblockedkeyword; - a regular expression (
~...) that is not anchored with^, that does not end the host name, or that leaves part of the host's registrable domain to the client, such as the unescaped dots in~^www.example.com/; - a name with a trailing wildcard, such as
example.*.
Why this is a problem
Any page can make the browser leave out the Referer, for example with referrerpolicy="no-referrer", and none accepts that. blocked accepts a Referer that does not start with http:// or https://, which browsers rarely send.
NGINX matches a regular expression anywhere in the Referer after its scheme. ~\.example\.com also accepts https://www.example.com.evil.net/, and https://evil.net/www.example.com when the attacker's page sends its full URL (referrerpolicy="unsafe-url"). ~^www\.example\.com still accepts www.example.com.evil.net, ~^www.example.com/ accepts wwwxexample.com, and example.* accepts example.evil.net.
Bad configuration
valid_referers none server_names *.example.com ~\.example\.com example.*;
if ($invalid_referer) {
return 403;
}
Better configuration
valid_referers server_names *.example.com ~^(www\.)?example\.org/;
if ($invalid_referer) {
return 403;
}
Anchor every regular expression with ^ and end the host name with / or :. If missing referers must be allowed for user experience, referer validation is not a reliable security boundary for that endpoint.
How severity is determined
- HIGH:
none. - MEDIUM: regular expressions or trailing wildcards that also match other sites, reported once per directive.
- LOW:
blockedwithoutnone.
Additional notes
- Names that
server_namesadds from the server'sserver_nameare not checked. - NGINX recognizes
none,blockedandserver_namesonly in lowercase;NONEis read as a host name.