Skip to content

Commit 8660193

Browse files
[AssetMapper] Adding info for CSP, recommending script-src 'strict-dynamic'
Page: https://symfony.com/doc/6.4/frontend/asset_mapper.html#handling-css I think there should be a clear recommendation for people using a Content-Security-Policy. Is `script-src 'strict-dynamic'` really the way to go? It's not possible for AssetMapper to just omit those empty entries, is it?
1 parent b29856d commit 8660193

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

frontend/asset_mapper.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,14 @@ the page as ``link`` tags in the order they were imported.
476476
.. note::
477477

478478
Importing a CSS file is *not* something that is natively supported by
479-
JavaScript modules. AssetMapper makes this work by adding a special importmap
480-
entry for each CSS file. These special entries are valid, but do nothing.
479+
JavaScript modules. AssetMapper makes this work by adding an empty importmap
480+
entry for each CSS file, e.g. ``"/assets/app.css": "data:application/javascript,",``.
481+
These special entries are valid, but do nothing.
481482
AssetMapper adds a ``<link>`` tag for each CSS file, but when JavaScript
482483
executes the ``import`` statement, nothing additional happens.
484+
When using a **Content-Security-Policy** with ``script-src 'self'``, this
485+
will trigger an error because of the ``data:`` URL. You can either just
486+
ignore the error, or lower the rule to ``script-src 'strict-dynamic'``.
483487

484488
.. _asset-mapper-3rd-party-css:
485489

0 commit comments

Comments
 (0)