AccessLogMiddleware (voice_mode/serve_middleware.py)

voicemode · voice_mode/serve_middleware.py · python · MIT
auth

HTTP/SSE middleware for IP allowlisting and token authentication in Starlette apps.

# Source: https://github.com/mbailey/voicemode | License: MIT | Copyright 2026 Mike Bailey
# Provided via justclaw.it.com; keep this notice with the code.
"""Middleware for VoiceMode HTTP/SSE server.

This module provides middleware to restrict access to the VoiceMode server:

1. IPAllowlistMiddleware - Restrict access based on client IP addresses.
   Supports CIDR notation for flexible IP range configuration. The allowlist
   is checked against the direct TCP peer; X-Forwarded-For is only honored
   when the peer is a configured trusted proxy (GHSA-2qvv-vjq9-g5r4).

2. TokenAuthMiddleware - Bearer token authentication via Authorization header.
   Validates Bearer tokens for API-style authentication.

Usage:
    from voice_mode.serve_middleware import (
        IPAllowlistMiddleware,
     

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key