CORS is not checked when browsing files. check origin now https://github.com/jupyter-server/jupyter_server/issues/1459#1465
Conversation
|
@gogasca Thanks for the issue and the PR. I've been reading it, and agree that the Happy for any input you have on the above, and thanks again! |
|
Thanks @vidartf I will test using |
gogasca
left a comment
There was a problem hiding this comment.
Change self.check_origin() to check_referer()
|
After changing: Change self.check_origin() to check_referer() many tests cases are broken, reverting back to self.check_origin() |
|
@vidartf can you PTAL again? |
1 similar comment
|
@gogasca apologies that this has taken so long to review. I updated the top level comment to give more information here. @vidartf You raise a valid concern about consistency with existing behavior. Here's my analysis: Key Differences Between Methods
The Trade-offYour suggestion to use check_referer() for GET/HEAD requests is technically correct for consistency, but
My Recommendation
try:
if self.request.method in {"GET", "HEAD"}:
if not self.check_referer():
raise web.HTTPError(404)
else:
if not self.check_origin():
raise web.HTTPError(404)
return super().check_xsrf_cookie()
except web.HTTPError as e:
# Existing fallback logic remains unchanged
ConclusionI think the current PR is acceptable as-is for the security fix. The architectural improvement (using |
|
Thank you @gogasca for your patience here! |
Add check_origin check during check_xsrf_cookie for files.
Details: #1459
Summary
This PR addresses a CORS bypass vulnerability in the /files endpoint. The issue allows attackers to bypass
configured CORS restrictions (allow_origin_pat) by exploiting the XSRF token validation flow.
The Vulnerability
The current check_xsrf_cookie() method in base/handlers.py:537 only calls super().check_xsrf_cookie() (Tornado's
XSRF validation) without first checking if the request origin is allowed. This allows attackers to:
Risk Assessment: