Skip to content

Commit 0be4ac5

Browse files
authored
Merge pull request #135 from agent-diff-bench/fixes-kdd
Redirect for file download
2 parents 5857db0 + 0b2e0aa commit 0be4ac5

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

backend/src/platform/api/middleware.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,30 @@ async def dispatch(self, request: Request, call_next) -> Response:
102102
status_code=status.HTTP_400_BAD_REQUEST,
103103
)
104104

105+
# Box /download paths are reached via 302 redirect from the
106+
# authenticated /content endpoint. HTTP clients strip auth
107+
# headers on redirect (per RFC 9110), so we skip the API-key
108+
# check here — mirroring how real Box returns a pre-signed CDN
109+
# URL that needs no Authorization header.
110+
is_download_redirect = "/download" in path
111+
105112
api_key_hdr = request.headers.get("X-API-Key") or request.headers.get(
106113
"Authorization"
107114
)
108115

109-
if not api_key_hdr and not is_dev_mode():
116+
if not api_key_hdr and not is_download_redirect and not is_dev_mode():
110117
return JSONResponse(
111118
{"ok": False, "error": "not_authed"},
112119
status_code=status.HTTP_401_UNAUTHORIZED,
113120
)
114121

115122
t_auth_start = time.perf_counter()
116-
principal_id = await get_principal_id(api_key_hdr, action="api_request")
123+
if api_key_hdr:
124+
principal_id = await get_principal_id(api_key_hdr, action="api_request")
125+
elif is_download_redirect:
126+
principal_id = "download-redirect"
127+
else:
128+
principal_id = "dev-user"
117129
t_auth_ms = (time.perf_counter() - t_auth_start) * 1000
118130

119131
t_meta_start = time.perf_counter()

0 commit comments

Comments
 (0)