Using the Leftmost Value of X-Forwarded-For as a Rate Limit Key Can Be Bypassed Through Spoofing
機械翻訳 / Machine-translated
機械翻訳 / Machine-translated
The login attempt limit for teacher accounts used the leftmost value of X-Forwarded-For as its key. Since the leftmost value can be spoofed, it could be bypassed simply by changing the value on every request. Here is an example of how it was fixed: reading from the rightmost value appended by GFE, making trusted proxy hops an environment variable, and grouping IPv6 addresses in /64 units.
The leftmost value of the X-Forwarded-For header is a value that clients can freely write, so using it as a rate limit key allows anyone to bypass the limit without ever triggering it, simply by changing the value each time. The login attempt limit for the shared teacher password (/api/auth/teacher-login) and the IP restriction for provisioning were both using this leftmost value as their key, rendering them ineffective. The fix was to switch to reading from the rightmost value, based on the premise that Cloud Run's GFE (Google Front End) appends the actual connecting source IP to the end of the header.
Detailed instructions, verification steps, and frequently asked questions are summarized in the original article.