Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1070. Builds on #1063 (base branch), which restricted CORS.
CORS only hides responses from other sites. This PR closes the remaining ways a foreign page could reach the local API:
TrustedHostMiddlewarerefuses requests whoseHostis notlocalhost/127.0.0.1. NewALLOWED_HOSTSsetting for Docker and server deployments.HttpOnly,SameSite=Strictcookie when it serves/app/, or throughGET /api/v1/auth/launch(used by the Vite dev frontend). Every/api/request and websocket without it gets401/ close1008. A cookie was chosen because<img>, video and audio tags that point at the API cannot send headers.401 launch_secret_requiredafter a backend restart renews the cookie and retries once.127.0.0.1,ALLOWED_HOSTS, reverse proxy with authentication,API_TOKEN), comments in both Dockerfiles, anddocker-compose.demo.ymlreadsDASHAI_ALLOWED_HOSTS.Behavior changes
docker-compose.demo.ymlmust setDASHAI_ALLOWED_HOSTSto the name or IP users reach the server with, otherwise requests get400 Invalid host header.API_TOKENand anAuthorization: Bearerheader.Known limitation
SameSitetreats everylocalhostport as the same site, so a malicious page served from another port on the same machine would still get the cookie attached. This is far narrower than "any website", which is what this PR closes.Tests
test_trusted_host_security.py,test_launch_secret_security.py,test_api_token_setting.py. The rejection tests were confirmed to fail without the middleware.test_bart_regressioncases that fail locally on apytensorC compile error unrelated to this change./app/sets the cookie,API_TOKENbearer accepted.