fix(security): don't trust loopback socket as local when request arrives via reverse proxy

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-17 11:12:24 +07:00
co-authored by Cursor
parent 2a619655b8
commit da667836cc
2 changed files with 8 additions and 0 deletions
+3
View File
@@ -90,6 +90,9 @@ function isLoopbackHostname(h) {
}
export function isLocalRequest(request) {
// Stamped by custom-server.js when forwarding headers exist: request came through
// a reverse proxy, so the loopback socket is the proxy hop, not the end-user.
if (request.headers.get("x-9r-via-proxy")) return false;
// Trusted peer IP from TCP socket (custom-server.js); unspoofable. Primary anchor for "local".
const realIp = request.headers.get("x-9r-real-ip");
if (realIp) {