77from fastapi .middleware .cors import CORSMiddleware
88from fastapi_mcp import AuthConfig , FastApiMCP
99from uvicorn ._types import ASGI3Application , ASGIReceiveCallable , ASGISendCallable , Scope
10+ from starlette .middleware .base import BaseHTTPMiddleware
1011from auth import fetch_jwks_public_key , verify_auth
1112from models import Auth0Settings
1213from sandbox .routes import get_sandbox_api_router
@@ -60,6 +61,16 @@ async def __call__(self, scope: Scope, receive: ASGIReceiveCallable, send: ASGIS
6061 return await self .app (scope , receive , send )
6162
6263
64+ class SecurityHeadersMiddleware (BaseHTTPMiddleware ):
65+ async def dispatch (self , request , call_next ):
66+ response = await call_next (request )
67+ # Clickjacking protection
68+ response .headers ["X-Frame-Options" ] = "SAMEORIGIN"
69+ # Prevent MIME type sniffing
70+ response .headers ["X-Content-Type-Options" ] = "nosniff"
71+ return response
72+
73+
6374def run ():
6475 app = FastAPI (title = "SandboxApiMCP" , lifespan = lifespan )
6576 app .include_router (get_sandbox_api_router ())
@@ -71,6 +82,7 @@ def run():
7182 allow_headers = ["*" ],
7283 )
7384 app .add_middleware (ProxyHeadersMiddleware )
85+ app .add_middleware (SecurityHeadersMiddleware )
7486 fastapi_mcp = FastApiMCP (
7587 app ,
7688 name = "Neo4j Sandbox API MCP Server" ,
0 commit comments