Skip to content
This is the documentation for pieceofcake2/security-headers, a CakePHP 2.x plugin for pieceofcake2/cakephp. About this fork.

Presets ​

The presets are the classes of the plugin, in PieceOfCake2\SecurityHeaders\ContentSecurityPolicy, with the sources that a service needs in the Content Security Policy. List those that your pages use in contentSecurityPolicyAllow (see Allowing Other Sites):

php
use PieceOfCake2\SecurityHeaders\ContentSecurityPolicy\GoogleTagManager;
use PieceOfCake2\SecurityHeaders\ContentSecurityPolicy\YouTube;

Configure::write('SecurityHeaders', [
    'contentSecurityPolicyAllow' => [GoogleTagManager::class, YouTube::class],
]);

Tag Managers and Analytics ​

GoogleTagManager ​

The container of Google Tag Manager. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide. Checked every week.

DirectiveSources
script-srchttps://www.googletagmanager.com
img-srchttps://www.googletagmanager.com
connect-srchttps://www.googletagmanager.com https://www.google.com

Its snippet, with the nonce, which it also passes to the script that it loads, as in Google's guide:

php
<!-- In <head> of the layout -->
<script nonce="<?= h($this->SecurityHeaders->nonce()) ?>">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;var n=d.querySelector('[nonce]');
n&&j.setAttribute('nonce',n.nonce||n.getAttribute('nonce'));f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>

The custom JavaScript variables need 'unsafe-eval' in script-src: use custom templates instead if you can. Tag Assistant lists the resources that the policy blocks, in Page issues.

GoogleTagManagerPreview ​

The preview mode of Google Tag Manager.

From Google's guide.

DirectiveSources
script-srchttps://www.googletagmanager.com https://tagmanager.google.com
style-srchttps://www.googletagmanager.com https://tagmanager.google.com https://fonts.googleapis.com
img-srchttps://www.googletagmanager.com https://ssl.gstatic.com https://www.gstatic.com
font-srchttps://fonts.gstatic.com data:

GoogleAnalytics ​

Google Analytics, without the features of Google Ads. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide. Checked every week.

DirectiveSources
script-srchttps://www.googletagmanager.com
img-srchttps://www.googletagmanager.com https://*.google-analytics.com
connect-srchttps://www.googletagmanager.com https://*.google-analytics.com https://*.google.com

Without Tag Manager, its gtag.js snippet has an inline script: <script nonce="<?= h($this->SecurityHeaders->nonce()) ?>">.

GoogleAnalyticsWithAds ​

Google Analytics, with the features of Google Ads (Google Signals, remarketing). Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide.

DirectiveSources
script-srchttps://www.googletagmanager.com
img-srchttps://www.googletagmanager.com https://*.google-analytics.com https://*.google.com https://*.g.doubleclick.net
connect-srchttps://www.googletagmanager.com https://*.google-analytics.com https://*.google.com https://*.g.doubleclick.net https://pagead2.googlesyndication.com
frame-srchttps://www.googletagmanager.com

Add the domain of the country of your users, e.g. https://*.google.co.jp to img-src and connect-src: a policy cannot have a wildcard at the end of a host.

AdobeTags ​

The library of Adobe Experience Platform Tags (formerly Adobe Launch) on the host of Adobe.

From Adobe's guide.

DirectiveSources
script-srchttps://assets.adobedtm.com

Load the library asynchronously. Add the classes of its extensions, e.g. AdobeAnalytics, and the nonce for its custom code: set a data element of the nonce in the Core extension.

AdobeAnalytics ​

Adobe Analytics (AppMeasurement) with the Experience Cloud Identity Service.

From Adobe's guide.

DirectiveSources
script-srchttps://*.demdex.net https://cm.everesttech.net https://assets.adobedtm.com
img-srchttps://*.omtrdc.net https://*.2o7.net https://*.demdex.net https://cm.everesttech.net https://assets.adobedtm.com
connect-srchttps://*.omtrdc.net https://*.2o7.net https://*.demdex.net https://cm.everesttech.net https://assets.adobedtm.com
frame-srchttps://*.demdex.net

Add your tracking server if it is on a domain of yours (a CNAME).

AdobeWebSdk ​

The Web SDK of Adobe Experience Platform; *.demdex.net is for the migration of the visitors (idMigrationEnabled).

From Adobe's guide.

DirectiveSources
connect-srchttps://*.adobedc.net https://*.demdex.net

Add your edge domain if edgeDomain is a domain of yours (a CNAME).

Conversion Tags (CV) of the Ads ​

Google Ads: the conversions, the remarketing, the conversion linker and the user data. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide.

DirectiveSources
script-srchttps://www.googletagmanager.com https://www.googleadservices.com https://www.google.com
img-srchttps://www.googletagmanager.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://pagead2.googlesyndication.com https://www.google.com
connect-srchttps://www.googletagmanager.com https://www.googleadservices.com https://googleads.g.doubleclick.net https://pagead2.googlesyndication.com https://www.google.com https://ad.doubleclick.net
frame-srchttps://www.googletagmanager.com

Add the domain of the country of your users, e.g. https://www.google.co.jp to img-src and connect-src.

Floodlight ​

Floodlight, with its custom scripts. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide.

DirectiveSources
img-srchttps://www.googletagmanager.com https://ad.doubleclick.net https://ade.googlesyndication.com https://adservice.google.com
connect-srchttps://pagead2.googlesyndication.com https://www.google.com https://www.googleadservices.com https://ad.doubleclick.net
frame-srchttps://www.googletagmanager.com https://*.fls.doubleclick.net

MerchantCenter ​

Google Merchant Center. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From Google's guide.

DirectiveSources
script-srchttps://www.googletagmanager.com
img-srchttps://*.merchant-center-analytics.goog
connect-srchttps://*.merchant-center-analytics.goog

MetaPixel ​

The Meta Pixel (Facebook Pixel), for the ads of Facebook and Instagram. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the base code of Meta. Checked every week.

DirectiveSources
script-srchttps://connect.facebook.net
img-srchttps://www.facebook.com
connect-srchttps://www.facebook.com
frame-srchttps://www.facebook.com
form-actionhttps://www.facebook.com

Large events are posted with a form in a hidden frame to https://www.facebook.com/tr/, hence frame-src and form-action.

TikTokPixel ​

The TikTok Pixel. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the base code of TikTok. Checked every week.

DirectiveSources
script-srchttps://analytics.tiktok.com
img-srchttps://analytics.tiktok.com
connect-srchttps://analytics.tiktok.com https://analytics-ipv6.tiktokw.us

XPixel ​

The X Pixel (formerly Twitter Pixel) of X Ads. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the base code of X. Checked every week.

DirectiveSources
script-srchttps://static.ads-twitter.com
img-srchttps://analytics.twitter.com https://t.co
connect-srchttps://analytics.twitter.com https://t.co

LineTag ​

The LINE Tag of LINE Ads. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the base code of LINE. Checked every week.

DirectiveSources
script-srchttps://d.line-scdn.net https://tag.flvcdn.net
img-srchttps://tr.line.me
connect-srchttps://tr.line.me

YahooJapanAds ​

The conversion tags and the site retargeting tags of Yahoo! JAPAN Ads, of the search ads and the display ads, with the site general tag (ytag.js). Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the announcement of Yahoo! JAPAN Ads and the tags. Checked every week.

DirectiveSources
script-srchttps://s.yimg.jp https://b91.yahoo.co.jp https://b97.yahoo.co.jp https://b98.yahoo.co.jp https://b99.yahoo.co.jp
img-srchttps://b91.yahoo.co.jp https://b97.yahoo.co.jp https://b98.yahoo.co.jp https://b99.yahoo.co.jp https://apm.yahoo.co.jp
connect-srchttps://b91.yahoo.co.jp https://b97.yahoo.co.jp https://b98.yahoo.co.jp https://b99.yahoo.co.jp https://apm.yahoo.co.jp https://dm.slim02.jp

The tags of the search ads load their scripts from and send their events to b9x.yahoo.co.jp; those of the display ads send theirs to apm.yahoo.co.jp, and the site general tag some to dm.slim02.jp.

MicrosoftAds ​

The UET tag of Microsoft Advertising. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the base code of Microsoft. Checked every week.

DirectiveSources
script-srchttps://bat.bing.com
img-srchttps://bat.bing.com https://bat.bing.net
connect-srchttps://bat.bing.com https://bat.bing.net

Embedded Contents ​

GoogleMaps ​

The Maps JavaScript API of Google Maps. Turns on the nonce: its code has an inline script, see Inline Scripts and the Nonce.

From the guide of the Maps JavaScript API (the allowlist policy). Checked every week.

DirectiveSources
script-src'unsafe-eval' https://*.googleapis.com https://*.gstatic.com https://*.google.com https://*.ggpht.com https://*.googleusercontent.com blob:
img-srchttps://*.googleapis.com https://*.gstatic.com https://*.google.com https://*.googleusercontent.com data:
frame-srchttps://*.google.com
connect-srchttps://*.googleapis.com https://*.google.com https://*.gstatic.com data: blob:
font-srchttps://fonts.gstatic.com
style-src'unsafe-inline' https://fonts.googleapis.com
worker-srcblob:

It adds 'unsafe-eval' to script-src and 'unsafe-inline' to style-src, as the guide. The 'unsafe-inline' of script-src of the guide is left out: the inline script, e.g. the callback, needs the nonce. If you load the API from the domain of a country, e.g. maps.google.fr, add it.

GoogleMapsEmbed ​

A map of Google Maps embedded with an iframe: the Maps Embed API, or "Share" > "Embed a map".

From the embed code. Checked every week.

DirectiveSources
frame-srchttps://www.google.com

YouTube ​

The embedded players of YouTube, of www.youtube.com and www.youtube-nocookie.com (the privacy-enhanced mode), the IFrame Player API and the thumbnails of i.ytimg.com.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://www.youtube.com
img-srchttps://i.ytimg.com
frame-srchttps://www.youtube.com https://www.youtube-nocookie.com

Facebook ​

The JavaScript SDK of Facebook and its social plugins: the Page plugin, the embedded posts, the Like button, the comments.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://connect.facebook.net
frame-srchttps://www.facebook.com
style-src'unsafe-inline'

The SDK adds <style> elements, so it adds 'unsafe-inline' to style-src. The plugins are not drawn in a headless Chrome, so the check covers the SDK only.

Instagram ​

The embedded posts of Instagram.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://www.instagram.com
frame-srchttps://www.instagram.com
style-src'unsafe-inline'

The embed code has style attributes, so it adds 'unsafe-inline' to style-src. The posts are not drawn in a headless Chrome, so the check covers the script only.

X ​

The embedded posts, timelines and buttons of X (formerly Twitter); syndication.twitter.com is for the timelines.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://platform.twitter.com
frame-srchttps://platform.twitter.com https://syndication.twitter.com
style-src'unsafe-inline'

The script adds <style> elements, so it adds 'unsafe-inline' to style-src. The posts are not drawn in a headless Chrome, so the check covers the script only.

TikTok ​

The embedded videos and profiles of TikTok.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://www.tiktok.com https://*.ttwstatic.com https://*.tiktokcdn-us.com
style-src'unsafe-inline' https://*.ttwstatic.com https://*.tiktokcdn-us.com
frame-srchttps://www.tiktok.com
connect-srchttps://www.tiktok.com
img-srcdata:

Its files come from *.ttwstatic.com in Japan and from *.tiktokcdn-us.com in the United States: TikTok picks the CDN by the country of the user. The embed code has a style attribute, so it adds 'unsafe-inline' to style-src.

Line ​

The social plugins of LINE: the "Share" and "Add friend" buttons.

From the embed code. Checked every week.

DirectiveSources
script-srchttps://www.line-website.com
frame-srchttps://social-plugins.line.me
style-src'unsafe-inline'

The embed code has a style attribute and the script sets styles, so it adds 'unsafe-inline' to style-src.

See LICENSE for copyright and license information. Not affiliated with the Cake Software Foundation.