urstark commited on
Commit
4615138
·
1 Parent(s): 17ec854

feat: enforce strict Bearer Token auth for HF Space interactions

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -167,8 +167,12 @@ async def vault_media(request: VaultRequest, background_tasks: BackgroundTasks,
167
  return {"status": "accepted", "message": "Vaulting started"}
168
 
169
  @app.get("/proxy-stream/{file_id}")
170
- async def proxy_stream(file_id: str, type: str = "audio", secret: str = Header(None)):
171
- if secret != SECRET_TOKEN:
 
 
 
 
172
  raise HTTPException(status_code=401, detail="Unauthorized")
173
 
174
  async def stream_generator():
 
167
  return {"status": "accepted", "message": "Vaulting started"}
168
 
169
  @app.get("/proxy-stream/{file_id}")
170
+ async def proxy_stream(file_id: str, type: str = "audio", authorization: str = Header(None)):
171
+ if not authorization or not authorization.startswith("Bearer "):
172
+ raise HTTPException(status_code=401, detail="Unauthorized")
173
+
174
+ token = authorization.split(" ")[1]
175
+ if token != SECRET_TOKEN:
176
  raise HTTPException(status_code=401, detail="Unauthorized")
177
 
178
  async def stream_generator():