The Anti-CSRF Library fails to restrict token to a particular IP address when being behind a reverse-proxy/WAF
The Anti-CSRF library's option to bind a token to a client IP address relies on the server-side remote address variable, which returns the reverse proxy or WAF address when the application sits behind one. As a result the token is not tied to the real client IP, weakening the intended protection.
- Disclosed after 9 hours
The Anti-CSRF Library provides the ability to restrict token to a particular IP address using the variable "$hmac_ip".
When "$hmac_ip" is set to "true", the token is generated using the predefined variable "$_SERVER['REMOTE_ADDR']" which gives the IP address of the client. However, when the web server is behind a reverse-proxy/WAF/Load-balancer/whatever, which is nowadays often the case, this variable will always return the IP address of the reverse-proxy/WAF/Load-balancer/whatever, failing to restrict the token to the client real IP address.
In order to restrict the token to the user real IP address, the Anti-CSRF Library should also check for the X-Forwared-For HTTP header. However, be advised this header can easily be spoofed. To my knowledge, one cannot ensure a client real IP address.
Both version 1.0.0 and 2.0.0 are affected.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the library reads only the direct connection address instead of a trusted forwarded-for header, so behind a proxy all clients share the proxy's address.
Impact
The IP-binding feature of the CSRF token does not work behind a proxy or WAF, so a token is not restricted to the client's real address; the text notes that forwarded-for headers can be spoofed and a real client IP cannot be guaranteed.
What the attacker needed
Application behind a reverse proxy or WAF; IP binding option enabled
The fix
The library should also consider the X-Forwarded-For header when binding the token to an IP, while acknowledging that this header can be spoofed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A CSRF token is a secret value a website gives your browser so it can tell your requests apart from forged ones. This library can also tie that secret to your IP address, so a stolen token is useless from another machine. Behind a proxy or firewall, the server only sees the proxy's address, so every user looks the same and the IP check does nothing useful.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.