Skip to content

Commit adb7760

Browse files
authored
[flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter#191912)
When Windows Smart App Control (SAC), Windows Defender Application Control (WDAC), or Group Policy blocks execution of Flutter binaries (such as `dartaotruntime.exe` during frontend_server compilation), Dart's Win32 process runner raises a `ProcessException` with Win32 error code 4551 (`ERROR_APPLICATION_CONTROL_POLICY_BLOCK`), 1260 (`ERROR_ACCESS_DISABLED_BY_POLICY`), or 454 (`ERROR_SYSTEM_INTEGRITY_POLICY_VIOLATION`). Previously, `_handleWindowsException` did not recognize these error codes and returned `null`, which resulted in an unhandled `ProcessException` crash report (accounting for 354 crashes in Flutter 3.47.1). This PR catches these security and application control policy error codes in `_handleWindowsException` and surfaces a clean, actionable `ToolExit` instructing users to check their Windows Security Smart App Control, WDAC, or Group Policy settings and configure an exclusion for the Flutter SDK directory. Fixes flutter#191899
1 parent 6ad2029 commit adb7760

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎packages/flutter_tools/lib/src/base/error_handling_io.dart‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,9 @@ void _handleWindowsException(Exception e, String? message, int errorCode) {
14501450
const kAccessDenied = 5;
14511451
const kFatalDeviceHardwareError = 483;
14521452
const kDeviceDoesNotExist = 433;
1453+
const kApplicationControlPolicyBlocked = 4551;
1454+
const kAccessDisabledByPolicy = 1260;
1455+
const kSystemIntegrityPolicyViolation = 454;
14531456

14541457
// Catch errors and bail when:
14551458
final String? errorMessage = switch (errorCode) {
@@ -1478,6 +1481,13 @@ void _handleWindowsException(Exception e, String? message, int errorCode) {
14781481
'$message. The device was not found.'
14791482
'\n$e\n'
14801483
'Verify the device is mounted and try again.',
1484+
kApplicationControlPolicyBlocked ||
1485+
kAccessDisabledByPolicy ||
1486+
kSystemIntegrityPolicyViolation =>
1487+
'${message != null ? "$message. " : ""}An Application Control policy or security policy has blocked execution.\n'
1488+
'$e\n'
1489+
'Please verify your Windows Security Smart App Control, Application Control policy (WDAC), '
1490+
'or Group Policy settings, or add an exclusion for the Flutter SDK directory.',
14811491
_ => null,
14821492
};
14831493
_throwFileSystemException(errorMessage);

‎packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ Please ensure that the SDK and/or project is installed in a location that has re
986986
const kDeviceFull = 112;
987987
const kUserMappedSectionOpened = 1224;
988988
const kUserPermissionDenied = 5;
989+
const kApplicationControlPolicyBlocked = 4551;
990+
const kAccessDisabledByPolicy = 1260;
991+
const kSystemIntegrityPolicyViolation = 454;
989992

990993
testWithoutContext(
991994
'when PackageProcess throws an exception containing non-executable bits',
@@ -1180,6 +1183,49 @@ Please ensure that the SDK and/or project is installed in a location that has re
11801183
throwsToolExit(message: expectedMessage),
11811184
);
11821185
});
1186+
1187+
for (final (name, errorCode) in const <(String, int)>[
1188+
('Windows Application Control policy', kApplicationControlPolicyBlocked),
1189+
('Windows group policy', kAccessDisabledByPolicy),
1190+
('Windows system integrity policy violation', kSystemIntegrityPolicyViolation),
1191+
]) {
1192+
testWithoutContext('when blocked by $name', () {
1193+
final fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
1194+
FakeCommand(
1195+
command: const <String>['foo'],
1196+
exception: ProcessException('foo', const <String>[], 'Blocked', errorCode),
1197+
),
1198+
FakeCommand(
1199+
command: const <String>['foo'],
1200+
exception: ProcessException('foo', const <String>[], 'Blocked', errorCode),
1201+
),
1202+
FakeCommand(
1203+
command: const <String>['foo'],
1204+
exception: ProcessException('foo', const <String>[], 'Blocked', errorCode),
1205+
),
1206+
]);
1207+
1208+
final ProcessManager processManager = createProcessManager(
1209+
delegate: fakeProcessManager,
1210+
platform: windowsPlatform,
1211+
);
1212+
1213+
const expectedMessage =
1214+
'An Application Control policy or security policy has blocked execution.';
1215+
expect(
1216+
() async => processManager.start(<String>['foo']),
1217+
throwsToolExit(message: expectedMessage),
1218+
);
1219+
expect(
1220+
() async => processManager.run(<String>['foo']),
1221+
throwsToolExit(message: expectedMessage),
1222+
);
1223+
expect(
1224+
() => processManager.runSync(<String>['foo']),
1225+
throwsToolExit(message: expectedMessage),
1226+
);
1227+
});
1228+
}
11831229
});
11841230

11851231
group('ProcessManager on linux throws tool exit', () {

0 commit comments

Comments
 (0)