Skip to content

Commit e71ed18

Browse files
[stable] [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (#192254)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: #191899 ### Impact Description: When Windows Smart App Control (SAC), Windows Defender Application Control (WDAC), or Group Policy blocks execution of Flutter binaries (such as `dartaotruntime.exe` executing `frontend_server_aot.dart.snapshot`), the Flutter tool crashes with an unhandled `ProcessException` instead of providing an actionable error message. This was the #1 tool crash in Flutter 3.47.1 (accounting for 354 crashes / 16.9% of the top 10 crashes). This fix catches the policy block error codes and displays a clear `ToolExit` explaining how to configure exclusions in Windows Security. ### Changelog Description: [flutter/191899] When Windows Smart App Control or security policies block binary execution on Windows, gracefully handle the error with an actionable message instead of crashing. ### Workaround: Manually add an exclusion for the Flutter SDK directory in Windows Security / Smart App Control / WDAC settings, or disable Smart App Control. However, users experiencing the crash currently receive an unhandled stack trace without clear indication of why execution was blocked. ### Risk: ### Test Coverage: ### Validation Steps: 1. Run `flutter test test/general.shard/base/error_handling_io_test.dart` to verify that Windows error codes 4551, 1260, and 454 are mapped to the expected `ToolExit` message. 2. On a Windows machine with Smart App Control or AppLocker configured to block unsigned binaries in user space, run `flutter build` or compile a Flutter project to verify that the tool exits cleanly with the explanatory error message rather than crashing with an unhandled `ProcessException`.
1 parent e8113bf commit e71ed18

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
@@ -1449,6 +1449,9 @@ void _handleWindowsException(Exception e, String? message, int errorCode) {
14491449
const kAccessDenied = 5;
14501450
const kFatalDeviceHardwareError = 483;
14511451
const kDeviceDoesNotExist = 433;
1452+
const kApplicationControlPolicyBlocked = 4551;
1453+
const kAccessDisabledByPolicy = 1260;
1454+
const kSystemIntegrityPolicyViolation = 454;
14521455

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