Add CSP sources to the plugin

AI-generated summary

The discussion revolves around adding Content Security Policy (CSP) sources for Google AdSense to the advertising plugin to simplify setup for non-advanced users marianord. pfaffman supports this, citing personal experience with ads failing due to CSP issues. However, neil raises concerns about the adequacy and stability of such a list, noting that Google frequently changes its domains and that enabling these sources by default could pose security risks. marianord acknowledges the limitations but suggests providing guidance in the plugin documentation. Falco clarifies that CSP instructions were already added to the plugin documentation in September Falco. ljpp adds that restrictive CSP settings can break external scripts, including cookie consent tools, and emphasizes the danger of enabling such settings by default. neil concludes that the plugin cannot automate this due to the complexity and instability of Google’s domains, making it impractical to include a comprehensive list of sources.

According to Mitigate XSS Attacks with Content Security Policy it’s possible to add a set of sources to the CSP policies.

I think it would be a great thing to add a group of sources like the ones above for Google AdSense, that way the plugin is easier to setup for non-advanced users.

CSP Violation: 'https://partner.googleadservices.com'
CSP Violation: 'https://tpc.googlesyndication.com'
CSP Violation: 'https://pagead2.googlesyndication.com'
CSP Violation: 'https://adservice.google.com'
``

Agreed! I recently had ads stop working on a site for just this reason and it took me a while to track it down.

Is that actually enough? Seems like there are always other assets coming from other domains that cause more CSP violations even with the google*.com ones listed. And google is free to change where the ad assets come from at any time. Also it would be surprising if someone installs the plugin and suddenly they have all these permitted resources (adsense, ad manager, amazon, codefund, carbon ads, and anything else included in the plugin) added to their security settings without asking.

It’s not, but is a good start, Google also sends from localized domains as google.com.mx, or google.co.ve.

The other thing, would be to add the CSP impass to the plugin documentation, and let everyone to handle how to work it out.

That was added in last September: Discourse Advertising Plugin (Ads)

:raised_hand: Same here. It’s always dangerous (bad practice) to enable restrictive settings by default, especially for upgrades. Took a while a figure out what is broken.

(This also breaks external cookie consent scripts, which are super annoying but kind of a legal requirement)

We’re not going to give Google js the keys to your community by default, and we can’t add a suggested list of sources to add to CSP settings given how the official Google doc doesn’t include all the necessary sources and can change them at any time (and already has?). Having gone through this with a customer last week (adding 19 sources to get it working), enabling CSP while using Google ads is going to be painful and we can’t automate it in the plugin.