Skip to content

Commit 17c8aa1

Browse files
committed
Add several new fragments
1 parent b54b4ba commit 17c8aa1

File tree

12 files changed

+337
-1
lines changed

12 files changed

+337
-1
lines changed

src/Fragments/AdobeTagManager.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a adobe tag manager
11+
*/
12+
class AdobeTagManager implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
// This is a CDN for adobe tag manager
19+
'https://assets.adobedtm.com',
20+
'https://js.adsrvr.org',
21+
'https://insight.adsrvr.org',
22+
'https://*.adsrvr.org',
23+
])
24+
->addDirective(Directive::FRAME, [
25+
'https://insight.adsrvr.org',
26+
'https://*.adsrvr.org',
27+
])
28+
->addDirective(Directive::SCRIPT_ELEM, [
29+
// This is a CDN for adobe tag manager
30+
'https://assets.adobedtm.com',
31+
'https://js.adsrvr.org',
32+
'https://insight.adsrvr.org',
33+
'https://*.adsrvr.org',
34+
]);
35+
}
36+
}

src/Fragments/Dynatrace.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a Dynatrace
11+
*/
12+
class Dynatrace implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::CONNECT, [
18+
'https://*.dynatrace.com',
19+
'https://*.bf.dynatrace.com',
20+
])
21+
->addDirective(Directive::SCRIPT_ELEM, [
22+
'https://*.dynatrace.com',
23+
])
24+
->addDirective(Directive::SCRIPT, [
25+
'https://js-cdn.dynatrace.com',
26+
'https://*.dynatrace.com',
27+
]);
28+
}
29+
}

src/Fragments/FacebookPixel.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a Facebook pixel related resources
11+
*/
12+
class FacebookPixel implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
'https://connect.facebook.net',
19+
'https://www.facebook.com',
20+
])
21+
->addDirective(Directive::SCRIPT_ELEM, [
22+
'https://connect.facebook.net',
23+
'https://www.facebook.com',
24+
])
25+
->addDirective(Directive::CONNECT, [
26+
'https://connect.facebook.net',
27+
'https://www.facebook.com',
28+
'https://www.instagram.com',
29+
])
30+
->addDirective(Directive::FRAME, [
31+
'https://www.facebook.com',
32+
])
33+
->addDirective(Directive::FORM_ACTION, [
34+
'https://www.facebook.com/tr/',
35+
])
36+
->addDirective(Directive::IMG, [
37+
'https://connect.facebook.net',
38+
'https://www.facebook.com',
39+
]);
40+
}
41+
}

src/Fragments/GoogleAnalytics.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Policies\Policy;
7+
8+
/**
9+
* This allows you to have a Google analytics related resources
10+
*/
11+
class GoogleAnalytics implements Fragment
12+
{
13+
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
'https://*.google-analytics.com',
19+
])
20+
->addDirective(Directive::SCRIPT_ELEM, [
21+
'https://*.google-analytics.com',
22+
'https://*.googletagmanager.com',
23+
'https://www.googleadservices.com',
24+
])
25+
->addDirective(Directive::CONNECT, [
26+
'https://*.google-analytics.com',
27+
'https://*.analytics.google.com',
28+
'https://*.googletagmanager.com',
29+
'https://www.google.co.nz/ads/ga-audiences',
30+
'https://google.com',
31+
'https://*.google.com',
32+
'https://www.google.com.au',
33+
'https://www.googleadservices.com',
34+
'https://*.googleapis.com',
35+
])
36+
->addDirective(Directive::IMG, [
37+
'https://*.google-analytics.com',
38+
'https://*.googletagmanager.com',
39+
]);
40+
}
41+
42+
}

src/Fragments/GoogleRecaptcha.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a Google Recaptcha related resources
11+
*/
12+
class GoogleRecaptcha implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT_ELEM, [
18+
'*.google.com',
19+
'https://*.gstatic.com',
20+
'https://googleads.g.doubleclick.net',
21+
'https://*.googlesyndication.com',
22+
])
23+
->addDirective(Directive::CONNECT, [
24+
'*.google.com',
25+
'https://*.gstatic.com',
26+
'https://googleads.g.doubleclick.net',
27+
'https://*.googlesyndication.com',
28+
]);
29+
}
30+
}

src/Fragments/JQuery.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a jQuery CDN
11+
*/
12+
class JQuery implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
// This is a CDN for jQuery used from userforms
19+
'https://code.jquery.com',
20+
])
21+
->addDirective(Directive::SCRIPT_ELEM, [
22+
// This is a CDN for jQuery used from userforms
23+
'https://code.jquery.com',
24+
]);
25+
}
26+
}

src/Fragments/LinkedIn.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a LinkedIn related assets
11+
*/
12+
class LinkedIn implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
'https://*.licdn.com',
19+
])
20+
->addDirective(Directive::SCRIPT_ELEM, [
21+
'https://*.licdn.com',
22+
])
23+
->addDirective(Directive::CONNECT, [
24+
'https://*.linkedin.oribi.io',
25+
'https://*.linkedin.com',
26+
])
27+
->addDirective(Directive::IMG, [
28+
'https://*.linkedin.com',
29+
]);
30+
}
31+
}

src/Fragments/QualtricsSurvey.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a qualtrics survey
11+
*/
12+
class QualtricsSurvey implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::SCRIPT, [
18+
'https://*.qualtrics.com',
19+
])
20+
->addDirective(Directive::CONNECT, [
21+
'https://*.qualtrics.com',
22+
])
23+
->addDirective(Directive::SCRIPT_ELEM, [
24+
'https://*.qualtrics.com',
25+
]);
26+
}
27+
}

src/Fragments/TikTokPixel.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Silverstripe\CSP\Fragments;
4+
5+
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Fragments\Fragment;
7+
use Silverstripe\CSP\Policies\Policy;
8+
9+
/**
10+
* This allows you to have a TikTok Pixel.
11+
*/
12+
class TikTokPixel implements Fragment
13+
{
14+
public static function addTo(Policy $policy): void
15+
{
16+
$policy
17+
->addDirective(Directive::FRAME, [
18+
'bytedance:',
19+
'sslocal:',
20+
])
21+
->addDirective(Directive::SCRIPT, [
22+
'https://analytics.tiktok.com',
23+
])
24+
->addDirective(Directive::SCRIPT_ELEM, [
25+
'https://analytics.tiktok.com',
26+
])
27+
->addDirective(Directive::CONNECT, [
28+
'https://analytics.tiktok.com',
29+
])
30+
->addDirective(Directive::IMG, [
31+
'https://analytics.tiktok.com',
32+
]);
33+
}
34+
}

src/Fragments/Vimeo.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Silverstripe\CSP\Fragments;
44

55
use Silverstripe\CSP\Directive;
6+
use Silverstripe\CSP\Keyword;
67
use Silverstripe\CSP\Policies\Policy;
78

89
/**
@@ -16,6 +17,14 @@ public static function addTo(Policy $policy): void
1617
// We want to allow scripts loaded from here as they recommend using their embed player
1718
->addDirective(Directive::SCRIPT, 'player.vimeo.com')
1819
->addDirective(Directive::FRAME, "player.vimeo.com")
19-
->addDirective(Directive::CHILD, "player.vimeo.com");
20+
->addDirective(Directive::CHILD, [
21+
Keyword::SELF,
22+
'player.vimeo.com'
23+
])
24+
->addDirective(Directive::WORKER, [
25+
Keyword::SELF,
26+
'player.vimeo.com',
27+
'blob:',
28+
]);
2029
}
2130
}

0 commit comments

Comments
 (0)