Skip to content

Add the ability to pass a CSP nonce to flutter.js that will be used when loading additional scripts #126977

@jacobsimionato

Description

@jacobsimionato

Strict CSPs require that any script tags that are created have a nonce attribute that specifies the same nonce included in the CSP header, to ensure all scripts that are loaded are trusted. Currently, Flutter is only compatible with the weaker strict-dynamic mode.

Flutter loads many scripts dynamically, e.g. flutter.js loads main.dart.js, and main.dart.js loads additional parts. And the engine loads canvaskit etc. It'd be great if the developer could pass flutter.js a nonce, and then Flutter could use that when loading all additional scripts. E.g.

_flutter.loader.loadEntrypoint({
          entrypointUrl: 'my_app/main.dart.js',
          nonce: my_nonce,
          onEntrypointLoaded: function(engineInitializer) {
            engineInitializer.initializeEngine().then(function(appRunner) {
              appRunner.runApp();
            });
          }
        });

It's worth considering if Flutter can automatically find the right nonce to use somehow e.g. there are approaches internally that copy the nonce from other script tags in the DOM. Overall, though, I think adding it as an explicit parameter passed by the app developer seems less likely to cause breakages and confusion.

This is not blocking anyone at the moment, but it likely will eventually when an app that is already using a strict CSP wants to integrate Flutter without accepting a security regression.

See internal bug b/274360267 for more details.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listcustomer: googleVarious Google teamsplatform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions