mirror of
https://github.com/dtzp555-max/ocp.git
synced 2026-07-21 21:15:09 +00:00
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:
+4
-2
@@ -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) : "";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user