Spaces:
Sleeping
Sleeping
Fix mounted hosting routes with trusted HTTPS origin
Browse files- app.py +25 -1
- results/r4/hosting_cold.json +12 -8
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import subprocess
|
|
| 11 |
import tempfile
|
| 12 |
from importlib.metadata import version
|
| 13 |
from pathlib import Path
|
|
|
|
| 14 |
|
| 15 |
try: # Uploaded release is flat; repository imports use the namespace package.
|
| 16 |
from .droid_runtime import SDK_VERSION, provision_droid
|
|
@@ -178,6 +179,29 @@ def configure(state):
|
|
| 178 |
}
|
| 179 |
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
class PublicDeadline:
|
| 182 |
"""Bound model-facing requests; cancellation reaches SDK session cleanup."""
|
| 183 |
|
|
@@ -260,12 +284,12 @@ async def main():
|
|
| 260 |
)
|
| 261 |
api = create_app()
|
| 262 |
api.add_middleware(PublicDeadline)
|
|
|
|
| 263 |
api.add_api_route("/hosting", hosting_redirect, include_in_schema=False)
|
| 264 |
app = gr.mount_gradio_app(
|
| 265 |
api,
|
| 266 |
panel,
|
| 267 |
path="/hosting",
|
| 268 |
-
root_path=hosting_root(),
|
| 269 |
show_error=False,
|
| 270 |
ssr_mode=False,
|
| 271 |
mcp_server=False,
|
|
|
|
| 11 |
import tempfile
|
| 12 |
from importlib.metadata import version
|
| 13 |
from pathlib import Path
|
| 14 |
+
from urllib.parse import urlsplit
|
| 15 |
|
| 16 |
try: # Uploaded release is flat; repository imports use the namespace package.
|
| 17 |
from .droid_runtime import SDK_VERSION, provision_droid
|
|
|
|
| 179 |
}
|
| 180 |
|
| 181 |
|
| 182 |
+
class SpaceOrigin:
|
| 183 |
+
"""Restore HF's known HTTPS origin without trusting forwarded headers or IPs."""
|
| 184 |
+
|
| 185 |
+
def __init__(self, app):
|
| 186 |
+
self.app = app
|
| 187 |
+
root = hosting_root()
|
| 188 |
+
self.host = urlsplit(root).netloc if root else None
|
| 189 |
+
|
| 190 |
+
async def __call__(self, scope, receive, send):
|
| 191 |
+
if self.host and scope["type"] in ("http", "websocket"):
|
| 192 |
+
scope = {
|
| 193 |
+
**scope,
|
| 194 |
+
"scheme": "https" if scope["type"] == "http" else "wss",
|
| 195 |
+
"server": (self.host, 443),
|
| 196 |
+
"headers": [
|
| 197 |
+
(name, value) for name, value in scope["headers"]
|
| 198 |
+
if name.lower() not in (b"host", b"forwarded")
|
| 199 |
+
and not name.lower().startswith(b"x-forwarded-")
|
| 200 |
+
] + [(b"host", self.host.encode("ascii"))],
|
| 201 |
+
}
|
| 202 |
+
await self.app(scope, receive, send)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
class PublicDeadline:
|
| 206 |
"""Bound model-facing requests; cancellation reaches SDK session cleanup."""
|
| 207 |
|
|
|
|
| 284 |
)
|
| 285 |
api = create_app()
|
| 286 |
api.add_middleware(PublicDeadline)
|
| 287 |
+
api.add_middleware(SpaceOrigin)
|
| 288 |
api.add_api_route("/hosting", hosting_redirect, include_in_schema=False)
|
| 289 |
app = gr.mount_gradio_app(
|
| 290 |
api,
|
| 291 |
panel,
|
| 292 |
path="/hosting",
|
|
|
|
| 293 |
show_error=False,
|
| 294 |
ssr_mode=False,
|
| 295 |
mcp_server=False,
|
results/r4/hosting_cold.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
| 5 |
"lore/api.py": "07d3b2c6c1eaa6f84f8d0903290202a4535abe3e90aae8dd7004ebf8681f0537",
|
| 6 |
"lore/connection_pool.py": "171e352941015148d08183261c08662e775e979e3acdf6229e1958c319347735",
|
| 7 |
"lore/live_reader.py": "f9bf16ecc572bb5495b7c2709073a3e3446995bea790fe8b485fe6c70dbb7bdd",
|
| 8 |
-
"deploy/hf/app.py": "
|
| 9 |
"deploy/hf/droid_runtime.py": "3e19b7d41d89f6ac574e6a572ef3313c73caf365c049983d7f809416c1bc227a",
|
| 10 |
"deploy/hf/FACTORY_NOTICE.md": "439e746d435366851887de25ac46cfae4760f8ce2ee632dce57cd11d56d12fb2"
|
| 11 |
},
|
| 12 |
-
"checker_sha256": "
|
| 13 |
"uid": 1002,
|
| 14 |
"read_only_root": true,
|
| 15 |
"docker_socket": false,
|
|
@@ -27,11 +27,13 @@
|
|
| 27 |
"california_schools": 89
|
| 28 |
},
|
| 29 |
"graph_comparison": "exact node/edge record multisets, independent of response order",
|
| 30 |
-
"cold_start_seconds":
|
| 31 |
-
"restart_seconds": 5.
|
| 32 |
"real_launcher": true,
|
| 33 |
"frontend_javascript_served": true,
|
| 34 |
"gradio_mount": true,
|
|
|
|
|
|
|
| 35 |
"trained_certification_forbidden": true,
|
| 36 |
"trained_graph_unchanged_after_forbidden_write": true,
|
| 37 |
"private_file_requests_denied": true,
|
|
@@ -40,8 +42,10 @@
|
|
| 40 |
"metered_model_calls": 0,
|
| 41 |
"public_ports": 0,
|
| 42 |
"limitation": "Local isolated startup/restoration proof, not HF deployment or hosted teaching",
|
| 43 |
-
"source_commit": "
|
| 44 |
-
"container_image": "lore:hf-check-
|
| 45 |
-
"
|
| 46 |
-
"
|
|
|
|
|
|
|
| 47 |
}
|
|
|
|
| 5 |
"lore/api.py": "07d3b2c6c1eaa6f84f8d0903290202a4535abe3e90aae8dd7004ebf8681f0537",
|
| 6 |
"lore/connection_pool.py": "171e352941015148d08183261c08662e775e979e3acdf6229e1958c319347735",
|
| 7 |
"lore/live_reader.py": "f9bf16ecc572bb5495b7c2709073a3e3446995bea790fe8b485fe6c70dbb7bdd",
|
| 8 |
+
"deploy/hf/app.py": "ff34d1d7b103184f597a3d4069bf6d1d6615d1607a40396dda774b0f48476680",
|
| 9 |
"deploy/hf/droid_runtime.py": "3e19b7d41d89f6ac574e6a572ef3313c73caf365c049983d7f809416c1bc227a",
|
| 10 |
"deploy/hf/FACTORY_NOTICE.md": "439e746d435366851887de25ac46cfae4760f8ce2ee632dce57cd11d56d12fb2"
|
| 11 |
},
|
| 12 |
+
"checker_sha256": "8a626c11c4da1d9a3a7006adb8ad28a951bbf8d8a47edc4cfe012608efa6bd71",
|
| 13 |
"uid": 1002,
|
| 14 |
"read_only_root": true,
|
| 15 |
"docker_socket": false,
|
|
|
|
| 27 |
"california_schools": 89
|
| 28 |
},
|
| 29 |
"graph_comparison": "exact node/edge record multisets, independent of response order",
|
| 30 |
+
"cold_start_seconds": 22.31913371400151,
|
| 31 |
+
"restart_seconds": 5.026489444993786,
|
| 32 |
"real_launcher": true,
|
| 33 |
"frontend_javascript_served": true,
|
| 34 |
"gradio_mount": true,
|
| 35 |
+
"hosting_relative_redirect": true,
|
| 36 |
+
"hosting_https_origin": true,
|
| 37 |
"trained_certification_forbidden": true,
|
| 38 |
"trained_graph_unchanged_after_forbidden_write": true,
|
| 39 |
"private_file_requests_denied": true,
|
|
|
|
| 42 |
"metered_model_calls": 0,
|
| 43 |
"public_ports": 0,
|
| 44 |
"limitation": "Local isolated startup/restoration proof, not HF deployment or hosted teaching",
|
| 45 |
+
"source_commit": "41bdcf1bd834d81dfaeacbf07511c95f2eef21e0",
|
| 46 |
+
"container_image": "lore:hf-check-origin",
|
| 47 |
+
"recorded_at": "2026-11-15T23:00:27.614648+00:00",
|
| 48 |
+
"platform_environment": {
|
| 49 |
+
"SPACE_HOST": "lore-validation.hf.space"
|
| 50 |
+
}
|
| 51 |
}
|