<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>291734</bug_id>
          
          <creation_ts>2025-04-18 01:12:21 -0700</creation_ts>
          <short_desc>Shadow DOM inline/internal styles blocked by CSP</short_desc>
          <delta_ts>2026-02-28 11:55:54 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari 18</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 15</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Erik van der Plas">erik.vander.plas</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>frederik.riedel</cc>
    
    <cc>kiara_rose</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wilander</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2111764</commentid>
    <comment_count>0</comment_count>
    <who name="Erik van der Plas">erik.vander.plas</who>
    <bug_when>2025-04-18 01:12:21 -0700</bug_when>
    <thetext>We encountered an issue working on a web extension with a content script injecting a piece of UI on certain user-specified host pages. To render the UI, we create a Shadow DOM which is inserted into the host&apos;s body. We also include styles using the Emotion CSS-in-JS library, which inserts a style tag for styling our UI. However, in Safari, on pages with strict content security policies disallowing inline styles, the style tag is cleared along with the following console message:

&gt; Refused to apply a stylesheet because its hash, its nonce, or &apos;unsafe-inline&apos; does not appear in the style-src directive of the Content Security Policy.

We were wondering if this is desired behavior as we are operating inside the Shadow DOM: the content style is already guaranteed to be isolated from the host page style, and therefore one could argue that the CSP should not apply here. This also seems to be the case in other browsers. Either this is a WebKit bug or there should be an alternative solution, as I&apos;d say this is a common usage pattern for web extensions. This concerns style tags inside the Shadow DOM, but perhaps also by injection into the host page by a web extension content script (as is also required for loading @font-faces https://stackoverflow.com/questions/63710162/how-to-load-font-face-in-dynamically-loaded-styles-of-web-component-with-shadow/63717709#63717709).

Looking forward to some insights, or a fix :)

Best, Erik</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2113053</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-04-25 01:13:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/150015282&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2123027</commentid>
    <comment_count>2</comment_count>
    <who name="Kiara Rose">kiara_rose</who>
    <bug_when>2025-06-11 10:32:01 -0700</bug_when>
    <thetext>you should be able to use `&lt;style src=&apos;safari-web-extension://...&apos;&gt;` in the shadow DOM. it would require that resource to be a part of the `web_accessible_resources` in the manifest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2123028</commentid>
    <comment_count>3</comment_count>
    <who name="Erik van der Plas">erik.vander.plas</who>
    <bug_when>2025-06-11 10:38:17 -0700</bug_when>
    <thetext>Hi Kiara, thanks for you reply. I suppose you mean `&lt;link src=...`? However, in this case, we use runtime generated styles instead of a fixed CSS file. Also note my remark on font faces, which currently necessitates injecting directly into the host page. I am not convinced that this provides a solution for our extension, but in general also a common browser extension usage pattern. The behavior is also inconsistent with other browsers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2129992</commentid>
    <comment_count>4</comment_count>
    <who name="Frederik Riedel">frederik.riedel</who>
    <bug_when>2025-07-14 15:19:37 -0700</bug_when>
    <thetext>Hey Kiara!

I’m Frederik, we briefly met in the WWDC labs in Cupertino last month &amp; I showed you our app “one sec” and the issue with the browser extension we have on pages like mastodon.social that Erik described above.

Would love to hear if you have an update on this.

Does the WebKit team consider this behaves as expected, or is this something that is planned to be fixed?

This would be great to know so we can correctly inform users about this &amp; work on a workaround if necessary.

As additional information, this kind of issue does not reproduce on any other browser engine we’ve tested: Firefox, Chrome and Edge work fine intervening mastodon.social with one sec.

Thanks a lot for your great work &amp; help!

– Frederik</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2185867</commentid>
    <comment_count>5</comment_count>
    <who name="Frederik Riedel">frederik.riedel</who>
    <bug_when>2026-02-28 11:55:54 -0800</bug_when>
    <thetext>Hello everyone,

just wanted to let you know that this bug still reproduces on Safari 26  (macOS) throughout the latest beta of Safari – blocking our “one sec” Safari extension from working properly on many social media websites (e.g. mastodon.social).

Is there anything we can help with get this addressed?

Thanks a lot and have a nice day!

– Frederik</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>