Fix CSRF vulnerability in TCP mode by implementing strict origin validation#39
Draft
Fix CSRF vulnerability in TCP mode by implementing strict origin validation#39
Conversation
Co-authored-by: ericcurtin <1694275+ericcurtin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix host-side TCP support vulnerability in DMR API
Fix CSRF vulnerability in TCP mode by implementing strict origin validation
Oct 18, 2025
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
During a security assessment, Cure53 identified a critical CSRF vulnerability when Docker Model Runner (DMR) API is exposed on TCP port. The API had no authentication or origin validation, allowing arbitrary websites to make unauthorized requests and execute operations including:
Proof of Concept
A malicious website could execute requests to the local API:
When a user visited a malicious site, their browser would execute this request to their local Docker Model Runner instance.
Solution
Implemented strict origin validation with an allowlist-based approach, as recommended by Cure53. The fix leverages the existing CORS middleware infrastructure (
pkg/middleware/cors.go) which was already integrated but not properly enabled.Key Changes
Added
getAllowedOrigins()function inmain.goDMR_ORIGINSenvironment variable for custom configurationnilfor Unix socket mode (CORS not needed)Enabled CORS middleware
models.NewManager()to use allowed origins (previouslynil)scheduling.NewScheduler()to use allowed origins (previouslynil)Added comprehensive testing
getAllowedOrigins()functionUpdated documentation
Default Behavior
TCP Mode (when
MODEL_RUNNER_PORTis set):http://localhosthttp://127.0.0.1https://localhosthttps://127.0.0.1Unix Socket Mode (default):
Configuration
Users can customize allowed origins using the
DMR_ORIGINSenvironment variable:Security Impact
Before Fix:
After Fix:
Testing
Compliance
Migration Notes
For most users: No action required. The fix is enabled automatically and provides secure defaults.
For advanced users: If you need to allow external origins, use the
DMR_ORIGINSenvironment variable to explicitly configure allowed origins.Fixes the CSRF vulnerability reported by Cure53.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.