Surviving a Security Audit: Why We Built a HubSpot CSP Generator

Mat Baxter

Mat Baxter

3 min read

It usually starts with an email from a client’s IT department. They’ve just run a routine security audit, and the results are in: “We need to configure Content Security Policy (CSP) headers on the HubSpot site immediately.”

On paper, this sounds like a standard, straightforward request. In reality, for anyone who has ever had to manage a CSP on a modern marketing website, it is a complete nightmare.

We recently went through this exact scenario with a client. To keep their site secure and compliant, we had to lock down their headers. But the process of actually doing it in HubSpot proved so incredibly frustrating that we decided to build our own tool to fix it.

Here is why managing CSP strings will drive you crazy—and how our new free tool solves the problem.

The Problem: Why CSPs are a Web Developer's Nightmare

A Content Security Policy is an essential security layer that helps detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection. It works by essentially creating an "allowlist" of approved sources for executable scripts, images, and styles.

If a domain isn't explicitly on that list, the browser blocks it.

This is great for security, but it's terrible for modern marketing websites. Your HubSpot site isn't just loading content from HubSpot. It relies on a web of third-party tools: tracking scripts, analytics, CRM widgets, ad pixels, and more.

Building a CSP manually means you have to:

  1. Hunt down every single domain and subdomain used by your third-party tools.
  2. Format them into a massive, brittle, continuous text string separated by spaces.
  3. Pray you didn't miss a vital sub-domain (like stats.g.doubleclick.net for Google Analytics).

If you make one typo or miss one required domain, your analytics drop off, your chat widget disappears, or your site functionality breaks completely. Maintaining and updating that string every time the marketing team wants to add a new tool is tedious, error-prone, and a massive drain on developer time.

The Solution: The HubSpot CSP Generator

We realized that if we were struggling to manage these massive domain strings, other HubSpot agencies and developers were definitely pulling their hair out over it, too.

Instead of dealing with a wall of text, we built a UI-driven tool to automate the headache away.

With our HubSpot CSP Tool, you no longer have to guess which domains to allow. Instead, you simply add the services you actually use.

Currently supported services include:

  • The Google Suite (Ads, Analytics, Tag Manager, etc.)
  • LinkedIn Insights
  • Hotjar
  • Unicorn Studio

Note: If you're interested in adding your own custom services and rules, or adding to the domain list, please contact us.

How it Works: Total Transparency, Zero Guesswork

When you select a service, our tool automatically populates the final CSP string with every specific domain required to make that service function perfectly.

Because security teams need to know exactly what is being allowed on the network, the tool also features a full, transparent list of every domain it adds per service. You get the convenience of a "click and add" interface without sacrificing the strict oversight required by an audit. You are left with one perfectly formatted string, ready to paste directly into HubSpot's "Policy directives" box.

Pro-Tips for Implementing Your HubSpot CSP

If you are setting this up for the first time, there are two crucial steps you need to take to ensure you don't accidentally break your live website.

1. The "Test Header" Strategy

Even with a generator tool doing the heavy lifting, you should never blindly enforce a new Content Security Policy on a live marketing site.

Before committing your new CSP string, we highly recommend testing it using the Report-Only header (Content-Security-Policy-Report-Only). This tells the browser to monitor the policy and report any violations to your developer console, but it won't actually block anything from loading.

How we do it:

  1. Generate your baseline string using our tool.
  2. In HubSpot, go to Settings > Content > Domains and URLs
  3. Click the Actions dropdown for your primary domain and select Update domain security settings
  4. Click the Security headers tab and check the Content-Security-Policy-Report-Only
  5. Paste the output generated from our tool directly in the Policy directives field and click Save
  6. Browse your site, submit a HubSpot form, click your tracking links, and open your browser's developer console.
  7. If you see any red errors about blocked resources, note the missing domains, add them to your policy, and test again. Once the console is clear, you are ready to enforce!

Are these steps out of date? Let us know.

2. The "Enable Nonce" Gotcha

Inside HubSpot's CSP settings, you will see an option to "Enable nonce." A nonce (number used once) is a unique, randomly generated token added to your scripts so the browser knows they are safe and authorized to run. Enabling this is a fantastic idea for strict security.

However, there is a catch: HubSpot can only automatically apply this secure nonce to your scripts if you are using HubL's native asset loaders. You must load all of your custom scripts and styles using the require_js and require_css HubL tags. If you have hardcoded <script> tags sitting directly in your HTML templates or custom modules, HubSpot cannot attach the nonce to them, and your new CSP will block them from loading.

Security First: A Quick Disclaimer

Because every website environment is completely unique and security configurations are highly sensitive, our tool includes a mandatory "I agree to the terms and conditions" checkbox and a "Use at your own risk" alert. While we use this tool for our own clients and keep the domain lists as accurate as possible, it is vital that your own technical or IT teams review the final generated string in a staging or report-only environment before pushing it live to your HubSpot portal.

Stop Guessing, Start Generating

Better website security shouldn't mean broken marketing tools or hours of wasted developer time hunting down obscure tracking domains.

If you are staring down a security audit or are just tired of manually updating a giant text string in your HubSpot settings, we invite you to try out the generator.

Try the HubSpot CSP Tool Here

Was the tool helpful?

If the tool was helpful to you and your team, but you need to be able to customise additional policies, do let us know. If there's enough interest, we're keen to continue to develop this tool to allow you to manage your custom policies and services.

Mat Baxter

Mat Baxter

As Chief Technology Officer at Ever Wonder, I lead the agency's technical vision, driving innovative tech stacks and data strategies behind our clients' most successful campaigns.

Related posts

More food for thought