Skip to content

Validate incoming requests to DevTools server - #10082

Open
johnpryan wants to merge 2 commits into
flutter:masterfrom
johnpryan:validate-devtools-server-requests
Open

johnpryan wants to merge 2 commits into
flutter:masterfrom
johnpryan:validate-devtools-server-requests

Conversation

@johnpryan

@johnpryan johnpryan commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

The DevTools server (server_api.dart) now has a _validateRequest function that performs a variety of checks to prevent cross-site request forgery, DNS rebinding, and cross-origin attacks:

  • Prevents external websites from triggering local operations through cross-origin GET requests. Requests to the DevTools server are now required to be POST or OPTIONS. Web browsers will allow cross-origin GET requests through img tags or the fetch() API. Malicious websites could call api/notifyForVmServiceConnection and connect to a remote VM service, which could lead to CSRF attacks where DTD authentication tokens are read through /api/getDtdUri. 
  • Prevents DNS rebinding attacks by validating that the host header is within an allowlist of loopback addresses (localhost, 127.0.0.1, etc) and is not malformed to mitigate DNS rebinding.
  • Rejects requests where the Sec-Fetch-Site header is set to cross-site unless the Origin header is a valid loopback address. Otherwise, only same-origin, same-site, or none are allowed.

This makes progress towards:

The DevTools server (`server_api.dart` now has a `_validateRequest` function that performs a variety of checks to prevent cross-site request forgery and DNS rebinding:

* Prevents external websites from triggering local operations through cross-origin `GET` requests. Requests to the DevTools server are now required to be `POST` or `OPTIONS`.  Web browsers will allow cross-origin `GET` requests through `img` tags or the `fetch()` API. Malicious websites could call `api/notifyForVmServiceConnection` and connect to a remote VM service, which could lead to CSRF attacks where DTD authentication tokens are read through `/api/getDtdUri`. 
* Prevents DNS rebinding attacks by validating that the `host` header is within an allowlist of loopback addresses (`localhost`, `127.0.0.1`, etc) and is not malformed to mitigate DNS rebinding.
* Rejects requests where the `Sec-Fetch-Site` header is set to `cross-site` unless the `Origin` header is a valid loopback address. Otherwise, only `same-origin`, `same-site`, or `none` are allowed.
@johnpryan
johnpryan requested review from a team, bkonyi and kenzieschmoll as code owners November 9, 2026 21:00
@johnpryan
johnpryan requested review from srawlins and removed request for a team November 9, 2026 21:00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the security of the DevTools server APIs by requiring POST (or OPTIONS CORS preflight) requests and validating Host, Origin, and Sec-Fetch-Site headers in ServerApi.handle to mitigate CSRF, DNS rebinding, and cross-origin attacks. It introduces a custom X-DevTools-Request header to force CORS preflight requests in browsers, updates client-side requests to include this header, and adds comprehensive test coverage for the new validation logic. There are no review comments to assess, and I have no additional feedback to provide.

@srawlins srawlins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice new tests. I hate CORS stuff, but good to get right.

This branch has not been deployed

No deployments
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.

2 participants