Skip to content

Check Host, Origin, content type and body size in the detector service - #8

Merged
ichen27 merged 1 commit into
mainfrom
fix/service-host-origin-checks
Nov 15, 2026
Merged

ichen27 merged 1 commit into
mainfrom
fix/service-host-origin-checks

Conversation

@ichen27

@ichen27 ichen27 commented Nov 15, 2026

Copy link
Copy Markdown
Owner

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: only localhost, 127.0.0.1 and hostnames in DETECTOR_ALLOWED_HOSTS.
  • /api/detect requires application/json, refuses an Origin that does not match the host, and stops reading the body once it exceeds the limit.
  • The MCP endpoint is unchanged and still answers only for localhost.

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.sh passes (38 tests).

Risk

A deployment behind a reverse proxy must set DETECTOR_ALLOWED_HOSTS, or the page returns 400. The README says so.

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.
@ichen27
ichen27 merged commit 932d78f into main Nov 15, 2026
1 check passed
@ichen27
ichen27 deleted the fix/service-host-origin-checks branch November 15, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant