From 6467cdee3c10b5c2c5d5ca7ae43555259b95b82d Mon Sep 17 00:00:00 2001 From: Decobus Date: Sat, 19 Jul 2025 05:02:12 -0400 Subject: [PATCH] Allow internal network access without API key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Skip API key authentication for localhost and local network IPs - Maintain security for external access while preserving usability - Log internal network access for transparency - Supports localhost, 127.0.0.1, and 192.168.x.x ranges 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- middleware.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/middleware.ts b/middleware.ts index 5896c43..910dd00 100644 --- a/middleware.ts +++ b/middleware.ts @@ -18,7 +18,14 @@ export function middleware(request: NextRequest) { return NextResponse.next(); } - // Validate API key + // Skip authentication for localhost/internal requests (optional security) + const host = request.headers.get('host'); + if (host && (host.startsWith('localhost') || host.startsWith('127.0.0.1') || host.startsWith('192.168.'))) { + console.log('Allowing internal network access without API key'); + return NextResponse.next(); + } + + // Validate API key for external requests if (!apiKey || apiKey !== validKey) { return NextResponse.json( { error: 'Unauthorized. Valid API key required.' },