feat: localhost bypass auth in multi mode

Requests from 127.0.0.1/::1 skip authentication even in multi/shared
auth modes. Only remote (LAN) clients need API keys.

This simplifies local tool integration — IDEs and agents on the same
machine no longer need to configure Bearer tokens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 10:09:07 +10:00
co-authored by Claude Opus 4.6
parent 9f1a21f7ad
commit 3eecca35ce
+4 -2
View File
@@ -1041,10 +1041,12 @@ const server = createServer(async (req, res) => {
// 3-mode auth: none | shared | multi // 3-mode auth: none | shared | multi
const pathname = req.url.split("?")[0]; const pathname = req.url.split("?")[0];
const isPublicEndpoint = pathname === "/health" || pathname === "/dashboard"; const isPublicEndpoint = pathname === "/health" || pathname === "/dashboard";
let authKeyName = "local"; const remoteAddr = req.socket.remoteAddress || "";
const isLocalhost = remoteAddr === "127.0.0.1" || remoteAddr === "::1" || remoteAddr === "::ffff:127.0.0.1";
let authKeyName = isLocalhost ? "local" : "remote";
let authKeyId = null; let authKeyId = null;
if (!isPublicEndpoint) { if (!isPublicEndpoint && !isLocalhost) {
const auth = req.headers["authorization"] || ""; const auth = req.headers["authorization"] || "";
const token = auth.startsWith("Bearer ") ? auth.slice(7) : ""; const token = auth.startsWith("Bearer ") ? auth.slice(7) : "";