Repository navigation
Check Host, Origin, content type and body size in the detector service - #8
Merged
Merged
Conversation
The service now answers only for localhost and hostnames listed in DETECTOR_ALLOWED_HOSTS. The scoring API requires application/json, refuses a browser Origin that does not match the host, and stops reading a request body once it passes the size limit, so another website cannot start model work through a visitor's browser.
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.
Problem
The scoring API accepted any Host and Origin and read the whole request body before checking its size. A web page open in a browser on the same machine could have posted to it, including through DNS rebinding, and started model work on a memory-constrained machine.
Change
TrustedHostMiddleware: onlylocalhost,127.0.0.1and hostnames inDETECTOR_ALLOWED_HOSTS./api/detectrequiresapplication/json, refuses anOriginthat does not match the host, and stops reading the body once it exceeds the limit.Validation
Ran the service on a spare port and checked each case: local JSON 200, proxy host with matching origin 200, foreign host 400, foreign origin 403, non-JSON content type 415, oversized body 413, MCP with a proxy host 421, MCP locally 200.
bash ci/run.shpasses (38 tests).Risk
A deployment behind a reverse proxy must set
DETECTOR_ALLOWED_HOSTS, or the page returns 400. The README says so.