Skip to content

Turn proxy trust off for no, off and unknown AIKIDO_TRUST_PROXY values - #812

Open
iacobdaniel wants to merge 1 commit into
mainfrom
parse-trust-proxy-setting
Open

iacobdaniel wants to merge 1 commit into
mainfrom
parse-trust-proxy-setting

Conversation

@iacobdaniel

Copy link
Copy Markdown
Collaborator

Only 0 and false turned off trust in the client IP header. no, n, off or a typo kept trusting a header any client can set.

Only 0 and false turned it off, so no, n, off or a typo kept trusting a
header any client can set. As with false, the SSRF check then stops
treating requests to the app's own host as safe. Numbers and ranges keep
trusting the header.
Comment on lines +56 to +58
# Hop counts and proxy ranges trust the header, but don't change which IP is picked.
is_hop_count = value.isdecimal() and value != "0"
return is_hop_count or "." in value or ":" in value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium - Malformed proxy settings containing punctuation still trust spoofable headers

An invalid AIKIDO_TRUST_PROXY value that contains a dot or colon, such as not.a.valid.setting, still makes trust_proxy() return true because the parser tests characters rather than validating an IP range. On a directly exposed deployment, a client can then supply X-Forwarded-For and have that value used as its remote address, allowing it to rotate IPs and bypass per-IP rate limits despite the change's fail-closed intent.

Show fix
Suggested change
# Hop counts and proxy ranges trust the header, but don't change which IP is picked.
is_hop_count = value.isdecimal() and value != "0"
return is_hop_count or "." in value or ":" in value
# Hop counts and valid proxy ranges trust the header, but don't change which IP is picked.
is_hop_count = value.isdecimal() and value != "0"
if is_hop_count:
return True
try:
import ipaddress
ipaddress.ip_network(value, strict=False)
return True
except ValueError:
return False

More info - Reply on this comment to give feedback or ignore the issue.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant