Description
Goal
For Google's first party applications, using cleartext to communicate with a server is a launch blocker. To help Flutter applications detect such problems, we would like to explicitly ban cleartext http and only allow TLS traffic in HttpClient. Since there are legitimate use cases for cleartext transmission, it should also be possible to override this behavior via a security review.
Proposal
Many packages such as Flutter access dart:io directly for its network calls. So, if the app is loading network assets (such as an image), it could accidentally use cleartext without a problem. We can ensure that does not happen by banning HTTP in the lowest level possible in Dart. We could do this in the platform libraries by throwing an exception in dart:io#HttpClient
if scheme is set to HTTP. There are several attributes of this requirement that shapes the proposed implementation.
This is for client apps only. From dart:io#HttpClient
perspective, this just means iOS and Android (not server). We should ban cleartext if Platform.isIOS
or Platform.isAndroid
. Note that Web is out of scope and should be handled separately.
We need to allow overrides. I propose to create a new zone variable for "allowClearText" in HttpOverrides
. This would be easy to use and readable. It also fits existing usage pattern if we expand the purpose of HttpOverrides
beyond testing (it is already being used beyond testing by some clients).
Combining these proposals, we get:
-
Modify
HttpOverrides
to supportallowClearText
as a zone variable. -
Create an
_EmbedderConfig
class to contain a static configuration as a default. This will be overridden in embedders for iOS and Android. -
Modify
_HttpClient
to ban HTTP scheme only if:
(Zone.current[allowClearText] ?? _EmbedderConfig.allowClearText) == false
See this internal design doc go/disable-http-flutter-dd for a more detailed discussion of alternatives.