Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,12 @@ rag_service = RAGService()
|
|
| 20 |
metrics_service = MetricsService(settings.metrics_path)
|
| 21 |
_agent_slots = asyncio.Semaphore(settings.max_concurrent_agent_requests)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def get_rag_service() -> RAGService:
|
| 25 |
return rag_service
|
|
@@ -147,7 +153,16 @@ async def secure_origin(request: Request, call_next):
|
|
| 147 |
response.headers["X-Content-Type-Options"] = "nosniff"
|
| 148 |
response.headers["Referrer-Policy"] = "no-referrer"
|
| 149 |
response.headers["Permissions-Policy"] = "geolocation=(), microphone=(), camera=(), payment=()"
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
if protected or path.startswith("/admin"):
|
| 152 |
response.headers["Cache-Control"] = "no-store"
|
| 153 |
return response
|
|
|
|
| 20 |
metrics_service = MetricsService(settings.metrics_path)
|
| 21 |
_agent_slots = asyncio.Semaphore(settings.max_concurrent_agent_requests)
|
| 22 |
|
| 23 |
+
# Hugging Face displays a Space inside an iframe whose parent is
|
| 24 |
+
# huggingface.co. Only the public status pages may be framed there. Admin and
|
| 25 |
+
# API routes remain protected against framing/clickjacking.
|
| 26 |
+
_HF_PREVIEW_PATHS = {"/", "/health/live", "/health/ready"}
|
| 27 |
+
_HF_FRAME_ANCESTORS = "frame-ancestors 'self' https://huggingface.co https://*.huggingface.co"
|
| 28 |
+
|
| 29 |
|
| 30 |
def get_rag_service() -> RAGService:
|
| 31 |
return rag_service
|
|
|
|
| 153 |
response.headers["X-Content-Type-Options"] = "nosniff"
|
| 154 |
response.headers["Referrer-Policy"] = "no-referrer"
|
| 155 |
response.headers["Permissions-Policy"] = "geolocation=(), microphone=(), camera=(), payment=()"
|
| 156 |
+
if path in _HF_PREVIEW_PATHS:
|
| 157 |
+
# X-Frame-Options cannot express an allowlist. Omit it only on these
|
| 158 |
+
# harmless GET endpoints and use CSP's exact parent-origin allowlist.
|
| 159 |
+
response.headers.pop("X-Frame-Options", None)
|
| 160 |
+
response.headers["Content-Security-Policy"] = _HF_FRAME_ANCESTORS
|
| 161 |
+
else:
|
| 162 |
+
response.headers["X-Frame-Options"] = "SAMEORIGIN" if path.startswith("/admin") else "DENY"
|
| 163 |
+
response.headers["Content-Security-Policy"] = (
|
| 164 |
+
"frame-ancestors 'self'" if path.startswith("/admin") else "frame-ancestors 'none'"
|
| 165 |
+
)
|
| 166 |
if protected or path.startswith("/admin"):
|
| 167 |
response.headers["Cache-Control"] = "no-store"
|
| 168 |
return response
|