Code Gate CORS Exploit
The CodeGate API server on localhost had a CORS configuration that allowed any origin to make requests with credentials, and it lacked CSRF tokens. An attacker could host a malicious website that, when visited by a developer, would silently read chat history or change settings to route AI conversations through an attacker-controlled proxy.
tomcope.com
Published on tomcope.com
My current role at ControlPlane comes with some nice perks, one of them is I get 7 free dedicated self-learning days a year when I am free to pick any topic to learn about and sharpen my skills.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The CORS middleware was configured to allow all origins, credentials, methods and headers, and no CSRF protection was present.
Impact
An attacker could read chat history (potentially exposing source code or secrets), change CodeGate settings, or override the AI provider to send future chats to an attacker-controlled proxy, potentially leaking LLM API keys; these actions could be performed without authentication and without the user's knowledge.
What the attacker needed
CodeGate running on localhost; victim visits a malicious website
The fix
The CORS configuration should be restricted to trusted origins and CSRF tokens should be added; the author created a fork that removed the misconfigured CORS, but the original project was archived and not officially fixed.
How it was found
- Visit a malicious website on a different origin while CodeGate is running on localhost.
- Run JavaScript in the browser console that sends a fetch request to the CodeGate API endpoint.
- Observe that the request succeeds and is not blocked by CORS.
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 write-up has not been written yet. The Original tab links to the source.
CORS is a browser rule that normally stops one website from reading data from another. Here the local CodeGate tool told browsers to allow any website to talk to it, so a malicious page could quietly fetch the developer's chat history or change the tool's settings. The developer only had to visit the page; no clicks were needed.
What is CORS?
A permissive cross-origin policy lets another site read responses with the user's credentials.