Reject non-loopback Host in build_runner serve - #5092
Open
herdiyana256 wants to merge 1 commit into
Open
Conversation
davidmorgan
self-requested a review
August 31, 2026 11:42
davidmorgan
reviewed
Aug 31, 2026
davidmorgan
left a comment
Contributor
There was a problem hiding this comment.
In #5097 the _rejectCrossOrigin check addresses this problem but just for websockets; the version in this PR is better, as it only rejects if serving on loopback.
Please remove _rejectCrossOrigin from BuildUpdatesWebSocketHandler.
Contributor
|
Failure on CI is because of stale generated files unrelated to this PR--please merge from master and uploaded to get the needed updates so CI can run. Or if you prefer to rebase onto master that's okay, it's a small PR. Thanks! |
davidmorgan
reviewed
Aug 31, 2026
herdiyana256
force-pushed
the
fix/serve-loopback-host-validation
branch
from
August 31, 2026 16:18
f6f4aab to
9eac5f7
Compare
Author
|
Thanks for the review. Addressed all points and rebased onto master so CI has the up to date generated files:
|
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.
build_runner servebinds an HTTP server that streams build outputs, and by default binds to localhost so it is only reachable from the local machine. The request pipeline inServeHandler.handlerFordid not validate the Host or Origin header on the asset serving path; only the live reload WebSocket had an origin check. A loopback HTTP server with no Host validation is reachable through DNS rebinding: a page the developer visits can rebind its own hostname to a loopback address and then read the served application and its source maps cross origin.Concretely, with the server on
localhost:8080, a page onattacker.example.comthat rebinds its DNS to127.0.0.1can issue:This validates the Host and Origin headers when the server is bound to a loopback interface, rejecting requests whose Host is absent or non loopback and requests carrying a non loopback Origin. It mirrors the daemon asset server, which already does this:
serve_command.dartenables it whenever the bind hostname is loopback (thelocalhostdefault). When the user has explicitly bound a routable address such as--hostname 0.0.0.0the restriction is skipped, so intentional network serving is unaffected.Added tests in
serve_handler_test.dartcovering missing Host, non loopback Host, non loopback Origin, the allowed loopback case, and that the default unrestricted behavior is unchanged.