Description
There is a critical IP Spoofing / Rate Limit Bypass vulnerability in the application's AI Chat endpoint. This vulnerability allows an attacker to exhaust the server's AI token quota (Gemini, Groq, Mistral), causing a Billing DoS (Denial of Service).
Vulnerability Details:
The rate limiting mechanism in app/api/chat/route.ts relies on getClientIp from lib/api-utils.ts to identify the user's IP.
However, getClientIp unconditionally trusts the X-Forwarded-For HTTP header without verifying if the request came from a trusted proxy:
export function getClientIp(request: Request): string {
const forwarded = request.headers.get("x-forwarded-for");
if (forwarded) return forwarded.split(",")[0].trim();
return "unknown";
}
Exploitation Scenario:
- The AI Chat endpoint limits users to 20 requests per minute based on their IP.
- An attacker can write a simple script that sends a POST request to
/api/chat with a continuously changing, spoofed X-Forwarded-For header (e.g., X-Forwarded-For: 1.2.3.4, then 1.2.3.5).
- Since
getClientIp extracts the spoofed IP, the rate limiter treats every request as coming from a new user.
- The attacker bypasses the 20-request limit entirely and rapidly drains the platform's API credits, costing the repository owner money.
Impact
- Severity: High / Critical (depending on financial impact)
- Attack Vector: IP Spoofing
- Consequences: API Quota Exhaustion / Billing DoS
Proposed Fix
I have updated getClientIp to prioritize the X-Real-IP header, which is set securely by load balancers and reverse proxies (like Vercel) and cannot be easily spoofed by the client. I've prepared a PR with this fix.
Could you please assign this to me, @piyushdotcomm?
Labels to apply: bug, level 3, security, advanced
Description
There is a critical IP Spoofing / Rate Limit Bypass vulnerability in the application's AI Chat endpoint. This vulnerability allows an attacker to exhaust the server's AI token quota (Gemini, Groq, Mistral), causing a Billing DoS (Denial of Service).
Vulnerability Details:
The rate limiting mechanism in
app/api/chat/route.tsrelies ongetClientIpfromlib/api-utils.tsto identify the user's IP.However,
getClientIpunconditionally trusts theX-Forwarded-ForHTTP header without verifying if the request came from a trusted proxy:Exploitation Scenario:
/api/chatwith a continuously changing, spoofedX-Forwarded-Forheader (e.g.,X-Forwarded-For: 1.2.3.4, then1.2.3.5).getClientIpextracts the spoofed IP, the rate limiter treats every request as coming from a new user.Impact
Proposed Fix
I have updated
getClientIpto prioritize theX-Real-IPheader, which is set securely by load balancers and reverse proxies (like Vercel) and cannot be easily spoofed by the client. I've prepared a PR with this fix.Could you please assign this to me, @piyushdotcomm?
Labels to apply:
bug,level 3,security,advanced