Skip to content

Commit 0e41fbc

Browse files
authored
Merge pull request #4 from neo4j-contrib/development
Add SecurityHeadersMiddleware to enhance response security
2 parents f0850dc + 63cd2b7 commit 0e41fbc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ venv
22
*/venv
33
*/.venv
44
**/.env
5+
__pycache__/
56

67
# Mac/OSX
78
.DS_Store

src/sandbox_api_mcp_server/server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from fastapi.middleware.cors import CORSMiddleware
88
from fastapi_mcp import AuthConfig, FastApiMCP
99
from uvicorn._types import ASGI3Application, ASGIReceiveCallable, ASGISendCallable, Scope
10+
from starlette.middleware.base import BaseHTTPMiddleware
1011
from auth import fetch_jwks_public_key, verify_auth
1112
from models import Auth0Settings
1213
from 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+
6374
def 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

Comments
 (0)