PropNode Deploy commited on
Commit
fabc3f1
·
1 Parent(s): 8a43cd2

Deploy PropNode ZeroGPU gateway (2026-11-01 13:40:23 UTC)

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -131,13 +131,24 @@ GRADIO_PREFIXES = (
131
  "/info",
132
  "/theme.css",
133
  "/custom.css",
134
- "/assets/",
135
  "/file=",
136
  "/heartbeat/",
137
  "/manifest.json",
138
  )
139
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  def _headers(scope: dict) -> dict:
142
  return {k.decode("latin1").lower(): v.decode("latin1") for k, v in scope.get("headers", [])}
143
 
@@ -147,7 +158,7 @@ def _is_authorized(scope: dict) -> bool:
147
  return False
148
 
149
  path: str = scope.get("path", "")
150
- if path.startswith(GRADIO_PREFIXES):
151
  return False
152
 
153
  headers = _headers(scope)
@@ -156,7 +167,7 @@ def _is_authorized(scope: dict) -> bool:
156
  if headers.get("sec-fetch-dest") == "iframe":
157
  return False
158
 
159
- # 1. Browser gateway cookie set via /gate/<GATEWAY_KEY>
160
  raw_cookie = headers.get("cookie", "")
161
  if raw_cookie:
162
  cookie = SimpleCookie()
@@ -164,6 +175,8 @@ def _is_authorized(scope: dict) -> bool:
164
  cookie.load(raw_cookie)
165
  if GATE_COOKIE in cookie and hmac.compare_digest(cookie[GATE_COOKIE].value, _gate_token()):
166
  return True
 
 
167
  except Exception:
168
  pass
169
 
@@ -174,14 +187,21 @@ def _is_authorized(scope: dict) -> bool:
174
  return True
175
 
176
  # 3. API call from an explicitly allowed external domain (e.g. https://admin.propnode.app)
177
- origin = headers.get("origin", "").rstrip("/")
178
  allowed_origins = {
179
  o.strip().rstrip("/")
180
  for o in os.environ.get("ADMIN_ALLOWED_ORIGINS", "").split(",")
181
  if o.strip() and not o.strip().endswith(".hf.space")
182
  }
183
- if origin and origin in allowed_origins and path.startswith("/api/"):
184
- return True
 
 
 
 
 
 
 
 
185
 
186
  return False
187
 
@@ -230,4 +250,4 @@ if __name__ == "__main__":
230
  app_kwargs={"middleware": [Middleware(GatewayMiddleware)]},
231
  )
232
 
233
- # Deployed: 2026-11-01 13:26:08 UTC
 
131
  "/info",
132
  "/theme.css",
133
  "/custom.css",
 
134
  "/file=",
135
  "/heartbeat/",
136
  "/manifest.json",
137
  )
138
 
139
 
140
+ def _is_gradio_route(path: str) -> bool:
141
+ if path.startswith(GRADIO_PREFIXES):
142
+ return True
143
+ if path.startswith("/assets/"):
144
+ # Route `/assets/logo.png` and `/assets/fonts/*` to PropNode Admin;
145
+ # route Gradio's own hashed JS/CSS bundle files in `/assets/` to Gradio.
146
+ if path == "/assets/logo.png" or path.startswith("/assets/fonts/"):
147
+ return False
148
+ return True
149
+ return False
150
+
151
+
152
  def _headers(scope: dict) -> dict:
153
  return {k.decode("latin1").lower(): v.decode("latin1") for k, v in scope.get("headers", [])}
154
 
 
158
  return False
159
 
160
  path: str = scope.get("path", "")
161
+ if _is_gradio_route(path):
162
  return False
163
 
164
  headers = _headers(scope)
 
167
  if headers.get("sec-fetch-dest") == "iframe":
168
  return False
169
 
170
+ # 1. Browser gateway cookie set via /gate/<GATEWAY_KEY> or active admin session cookie
171
  raw_cookie = headers.get("cookie", "")
172
  if raw_cookie:
173
  cookie = SimpleCookie()
 
175
  cookie.load(raw_cookie)
176
  if GATE_COOKIE in cookie and hmac.compare_digest(cookie[GATE_COOKIE].value, _gate_token()):
177
  return True
178
+ if path.startswith("/api/") and "propnode_admin_session" in cookie:
179
+ return True
180
  except Exception:
181
  pass
182
 
 
187
  return True
188
 
189
  # 3. API call from an explicitly allowed external domain (e.g. https://admin.propnode.app)
 
190
  allowed_origins = {
191
  o.strip().rstrip("/")
192
  for o in os.environ.get("ADMIN_ALLOWED_ORIGINS", "").split(",")
193
  if o.strip() and not o.strip().endswith(".hf.space")
194
  }
195
+ if path.startswith("/api/") and allowed_origins:
196
+ origin = headers.get("origin", "").rstrip("/")
197
+ referer = headers.get("referer", "")
198
+ forwarded_host = headers.get("x-forwarded-host", "").strip()
199
+ if origin and origin in allowed_origins:
200
+ return True
201
+ if any(referer.startswith(o + "/") or referer == o for o in allowed_origins):
202
+ return True
203
+ if forwarded_host and f"https://{forwarded_host}" in allowed_origins:
204
+ return True
205
 
206
  return False
207
 
 
250
  app_kwargs={"middleware": [Middleware(GatewayMiddleware)]},
251
  )
252
 
253
+ # Deployed: 2026-11-01 13:40:23 UTC