Skip to content

Commit b187ff9

Browse files
authored
Captcha Services Presets (#160)
* A couple of Captcha services presets * Update README.md update presets table in readme
1 parent 3f95ca2 commit b187ff9

6 files changed

+45
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ This package ships with a few commonly used presets to get your started. *We're
158158
| `Fathom` | [usefathom.com](https://usefathom.com) |
159159
| `Google TLD's` | Allow all Google Top Level Domains for 'connect' and 'image' |
160160
| `Google` | Google Analytics & Tag Manager |
161-
| `GoogleFonts` | [fonts.google.com](https://fonts.google.com) |
161+
| `GoogleFonts` | [fonts.google.com](https://fonts.google.com) |
162+
| `GoogleRecaptcha` | [developers.google.com](https://developers.google.com/recaptcha) |
163+
| `Hcaptcha` | [hcaptcha.com](https://docs.hcaptcha.com) |
162164
| `HubSpot` | [hubspot.com](https://hubspot.com) (full suite) |
163165
| `Intercom` | [intercom.com](https://intercom.com/) |
164166
| `JsDelivr` | [jsdelivr.com](https://jsdelivr.com) |
@@ -169,7 +171,7 @@ This package ships with a few commonly used presets to get your started. *We're
169171
| `Stripe` | [stripe.com](https://stripe.com/) |
170172
| `TicketTailor` | [tickettailor.com](https://www.tickettailor.com) |
171173
| `Tolt` | [tolt.io](https://tolt.io) |
172-
| `Vimeo` | [vimeo.com](https://vimeo.com) |
174+
| `Vimeo` | [vimeo.com](https://vimeo.com) |
173175

174176
Register the presets you want to use for your application in `config/csp.php` under the `presets` or `report_only_presets` key.
175177

src/Presets/GoogleRecaptcha.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Spatie\Csp\Presets;
4+
5+
use Spatie\Csp\Directive;
6+
use Spatie\Csp\Policy;
7+
use Spatie\Csp\Preset;
8+
9+
class GoogleRecaptcha implements Preset
10+
{
11+
public function configure(Policy $policy): void
12+
{
13+
$policy
14+
->add(Directive::SCRIPT, ['www.google.com/recaptcha/', 'www.gstatic.com/recaptcha/'])
15+
->add(Directive::FRAME, ['www.google.com/recaptcha/', 'recaptcha.google.com/recaptcha/']);
16+
}
17+
}

src/Presets/Hcaptcha.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Spatie\Csp\Presets;
4+
5+
use Spatie\Csp\Directive;
6+
use Spatie\Csp\Policy;
7+
use Spatie\Csp\Preset;
8+
9+
class Hcaptcha implements Preset
10+
{
11+
public function configure(Policy $policy): void
12+
{
13+
$policy
14+
->add([Directive::SCRIPT, Directive::FRAME, Directive::STYLE, Directive::CONNECT], ['hcaptcha.com', '*.hcaptcha.com']);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
script-src www.google.com/recaptcha/ www.gstatic.com/recaptcha/
2+
frame-src www.google.com/recaptcha/ recaptcha.google.com/recaptcha/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
script-src hcaptcha.com *.hcaptcha.com
2+
frame-src hcaptcha.com *.hcaptcha.com
3+
style-src hcaptcha.com *.hcaptcha.com
4+
connect-src hcaptcha.com *.hcaptcha.com

tests/PresetTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ function (string $presetClass): void {
2828
Presets\Fathom::class,
2929
Presets\GoogleAnalytics::class,
3030
Presets\GoogleFonts::class,
31+
Presets\GoogleRecaptcha::class,
3132
Presets\GoogleTagManager::class,
3233
Presets\GoogleTlds::class,
34+
Presets\Hcaptcha::class,
3335
Presets\HubSpot::class,
3436
Presets\Intercom::class,
3537
Presets\JsDelivr::class,

0 commit comments

Comments
 (0)