Usage | laravel-csp-go | Spatie       

 SPATIE  

laravel-csp-go
==============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-csp-go](https://spatie.be/docs/laravel-csp-go/v1)  Usage

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-csp-go/v1) 

  Usage    
- [ Introduction ](https://spatie.be/docs/laravel-csp-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-csp-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-csp-go/v1/usage)
- [ Creating a preset ](https://spatie.be/docs/laravel-csp-go/v1/creating-a-preset)
- [ Using inline scripts and styles ](https://spatie.be/docs/laravel-csp-go/v1/using-inline-scripts-and-styles)
- [ Outputting a CSP policy as a meta tag ](https://spatie.be/docs/laravel-csp-go/v1/outputting-a-csp-policy-as-a-meta-tag)
- [ Reporting CSP errors ](https://spatie.be/docs/laravel-csp-go/v1/reporting-csp-errors)
- [ Testing ](https://spatie.be/docs/laravel-csp-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-csp-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-csp-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-csp-go/v1/support-us)

 Usage
=====

###  On this page 

1. [ Included presets ](#content-included-presets)

This package ships with a few commonly used presets to get you started. We're happy to receive PRs for more services!

Register the presets you want to use for your application in `Policy.Presets` or `ReportOnly.Presets`:

```
Packages: []laravel.Package{
    csp.New(func(cfg *csp.Config) {
        cfg.Policy.Presets = []csp.Preset{csp.Basic{}, csp.GoogleFonts{}, csp.Stripe{}}
        cfg.ReportOnly.Presets = []csp.Preset{MyPreset{}}
    }),
},
```

If you have app-specific needs or the service you're integrating isn't included in this package, you can [create your own preset](creating-a-preset). You can also register global directives:

```
csp.New(func(cfg *csp.Config) {
    cfg.Policy.Directives = []csp.DirectiveConfig{
        {Directives: []csp.Directive{csp.Script, csp.Style}, Values: []string{csp.UnsafeEval, csp.UnsafeInline}},
    }
    cfg.ReportOnly.Directives = []csp.DirectiveConfig{
        {Directives: []csp.Directive{csp.Script}, Values: []string{csp.Self}},
    }
})
```

Directives are applied after presets. Setting `cfg.Policy = csp.PolicyConfig{}` disables the enforcing policy while leaving report-only configuration available. A reporting URL alone does not make an empty policy active.

Included presets
--------------------------------------------------------------------------------------------------------

`Basic`, `AdobeFonts`, `Alchemer`, `Algolia`, `Bootstrap`, `BunnyFonts`, `Chargebee`, `Clarity`, `CloudflareCdn`, `CloudflareTurnstile`, `CloudflareWebAnalytics`, `Cookiebot`, `Fathom`, `Featurebase`, `Firebase`, `GoogleAds`, `GoogleAnalytics`, `GoogleFonts`, `GoogleLookerStudio`, `GoogleMaps`, `GoogleRecaptcha`, `GoogleTagManager`, `GoogleTlds`, `Hcaptcha`, `HeapAnalytics`, `Hireroad`, `HotJar`, `HubSpot`, `Intercom`, `JQuery`, `JsDelivr`, `LaravelPulse`, `Maze`, `MetaPixel`, `Plain`, `PlausibleAnalytics`, `Posthog`, `Rollbar`, `Sentry`, `Stripe`, `SurveyMonkey`, `ThereThere`, `TicketTailor`, `Tolt`, `TrackJs`, `Vimeo`, `VisualWebsiteOptimizer`, and `Whereby`.

All names are exported types in the root `csp` package. Instantiate them with `{}`, for example `csp.GoogleFonts{}`. Each preset's serialized policy is checked against an independent fixture from the PHP package.

### Laravel Pulse

The `LaravelPulse` preset is a standalone policy for the PHP Pulse dashboard's resources. Use it only on a route serving compatible assets, not in the global preset list or combined with `Basic`.

Pulse uses inline scripts and styles, and its bundled Livewire/Alpine JavaScript requires `unsafe-eval`. This preset allows those features while blocking other resources by default. It allows same-origin connections, Bunny's Figtree fonts, data images, Gravatar avatars, and Unavatar icons. Custom cards or avatar URLs may need a custom preset with additional sources.

This preset does not install Laravel Pulse in Go.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
