Allow internal network access without API key
Some checks failed
Lint and Build / build (20) (pull_request) Failing after 20s
Lint and Build / build (22) (pull_request) Failing after 33s

- 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 <noreply@anthropic.com>
This commit is contained in:
Decobus 2025-07-19 05:02:12 -04:00
parent afc6f5f3a8
commit 6467cdee3c

View file

@ -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.' },