Michael Rabinovich Cursor commited on
Commit
f17ac64
·
1 Parent(s): 5eaf6b8

fix(oauth): use real HF OAuth on this Docker Space instead of mock login

Browse files

Gradio's get_space() only returns truthy when SYSTEM=="spaces", which HF
sets on Gradio-SDK Spaces but not on sdk: docker Spaces like this one.
Without it, mount_gradio_app wired up Gradio's MOCK OAuth routes: they
never contact hf.co and log every visitor in as the container token's
owner (our HF_TOKEN account). Because that account is in CADGENBENCH_ADMINS,
this leaked the "Logout (michaelr27)" identity to all visitors and granted
admin to anyone who completed the (mock) login.

Set SYSTEM=spaces when running on a Space (SPACE_ID present) so the real
hf_oauth: true flow runs; left unset locally so the local mock login still
works for dev.

Co-authored-by: Cursor <cursoragent@cursor.com>

Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -1332,6 +1332,20 @@ app.add_api_route(
1332
  serve_task_input,
1333
  methods=["GET"],
1334
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1335
  app = gr.mount_gradio_app(app, blocks, path="/")
1336
 
1337
 
 
1332
  serve_task_input,
1333
  methods=["GET"],
1334
  )
1335
+ # Gradio picks REAL Hugging Face OAuth vs. a local "mock" login via
1336
+ # ``gradio.utils.get_space()``, which is only truthy when ``SYSTEM ==
1337
+ # "spaces"``. HF sets that on Gradio-SDK Spaces but NOT on ``sdk: docker``
1338
+ # Spaces like this one. Without it, ``mount_gradio_app`` wires up the MOCK
1339
+ # OAuth routes, which never contact hf.co and instead log every visitor in
1340
+ # as the container token's owner (our ``HF_TOKEN`` account) -- leaking that
1341
+ # identity into the LoginButton and, since that account is in
1342
+ # ``CADGENBENCH_ADMINS``, handing every visitor admin. Force it on only when
1343
+ # we're actually running on a Space (``SPACE_ID`` is HF-injected on all
1344
+ # Spaces, Docker included) so the real ``hf_oauth: true`` flow runs; locally
1345
+ # (no ``SPACE_ID``) it stays unset so Gradio's local mock login still works
1346
+ # for dev. Must precede the mount, which is what triggers ``attach_oauth``.
1347
+ if os.environ.get("SPACE_ID") and os.environ.get("SYSTEM") != "spaces":
1348
+ os.environ["SYSTEM"] = "spaces"
1349
  app = gr.mount_gradio_app(app, blocks, path="/")
1350
 
1351