Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

More reverts for insecure http policy since the Dart implementation is reverted #25623

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions lib/io/dart_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,8 @@ namespace flutter {

void DartIO::InitForIsolate(bool may_insecurely_connect_to_all_domains,
std::string domain_network_policy) {
Dart_Handle io_lib = Dart_LookupLibrary(ToDart("dart:io"));
Dart_Handle result = Dart_SetNativeResolver(io_lib, dart::bin::LookupIONative,
dart::bin::LookupIONativeSymbol);
FML_CHECK(!LogIfError(result));

Dart_Handle embedder_config_type =
Dart_GetNonNullableType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
FML_CHECK(!LogIfError(embedder_config_type));

Dart_Handle allow_insecure_connections_result = Dart_SetField(
embedder_config_type, ToDart("_mayInsecurelyConnectToAllDomains"),
ToDart(may_insecurely_connect_to_all_domains));
FML_CHECK(!LogIfError(allow_insecure_connections_result));

Dart_Handle dart_args[1];
dart_args[0] = ToDart(domain_network_policy);
Dart_Handle set_domain_network_policy_result = Dart_Invoke(
embedder_config_type, ToDart("_setDomainPolicies"), 1, dart_args);
FML_CHECK(!LogIfError(set_domain_network_policy_result));
// We should be setting fields on dart:io's _EmbedderConfig but they have
// been reverted due to https://github.com/flutter/flutter/issues/72723.
}

} // namespace flutter
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.security.NetworkSecurityPolicy;
import androidx.annotation.NonNull;
import java.io.IOException;
import org.json.JSONArray;
Expand Down Expand Up @@ -148,9 +147,10 @@ public static FlutterApplicationInfo load(@NonNull Context applicationContext) {
ApplicationInfo appInfo = getApplicationInfo(applicationContext);
// Prior to API 23, cleartext traffic is allowed.
boolean clearTextPermitted = true;
if (android.os.Build.VERSION.SDK_INT >= 23) {
clearTextPermitted = NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted();
}
// We should check NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted() from the OS
// as well to enforce it at the dart:io level but have reverted that feature due to
// https://github.com/flutter/flutter/issues/72723. Checking it is an expensive call that
// wouldn't be used in dart:io.

return new FlutterApplicationInfo(
getString(appInfo.metaData, PUBLIC_AOT_SHARED_LIBRARY_NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void itGeneratesCorrectApplicationInfoWithDefaultManifest() {

@Config(shadows = {ApplicationInfoLoaderTest.ShadowNetworkSecurityPolicy.class})
@Test
public void itVotesAgainstClearTextIfSecurityPolicySaysSo() {
public void itIgnoresSystemSecurityPolicyDueToIssue72723() {
FlutterApplicationInfo info = ApplicationInfoLoader.load(RuntimeEnvironment.application);
assertNotNull(info);
assertEquals(false, info.clearTextPermitted);
assertEquals(true, info.clearTextPermitted);
}

@Implements(NetworkSecurityPolicy.class)
Expand Down