# Securely fixing CSP errors in iFrame widget

**URL:** <https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907>\
**Category:** Questions\
**Created:** [April 24, 2026, 5:56pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907 "2026-04-24T17:56:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayB](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JayB](https://developer.squareup.com/forums/u/JayB)\
**Post date:** [April 24, 2026, 5:56pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/1 "2026-04-24T17:56:27Z")

</div>

I have some issues trying to clean up CSP errors when using the iFrame payment widget.

NOTE: I do not want to use unsafe-inline.

My current CSP

> default-src ‘self’;  
> script-src ‘self’ [https://sandbox.web.squarecdn.com](https://sandbox.web.squarecdn.com);  
> frame-src ‘self’ [https://sandbox.web.squarecdn.com](https://sandbox.web.squarecdn.com) ;  
> style-src ‘self’ [https://sandbox.web.squarecdn.com](https://sandbox.web.squarecdn.com) [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com) [https://d1g145x70srn7h.cloudfront.net](https://d1g145x70srn7h.cloudfront.net);  
> style-src-elem ‘self’ ‘sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=’ [https://fonts.googleapis.com](https://fonts.googleapis.com) [https://sandbox.web.squarecdn.com](https://sandbox.web.squarecdn.com) [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com) [https://d1g145x70srn7h.cloudfront.net](https://d1g145x70srn7h.cloudfront.net);  
> font-src ‘self’ [https://cash-f.squarecdn.com](https://cash-f.squarecdn.com) [https://fonts.googleapis.com](https://fonts.googleapis.com) [https://fonts.gstatic.com](https://fonts.gstatic.com) [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com) [https://d1g145x70srn7h.cloudfront.net](https://d1g145x70srn7h.cloudfront.net);  
> connect-src ‘self’ [https://pci-connect.squareupsandbox.com](https://pci-connect.squareupsandbox.com) [https://o160250.ingest.sentry.io](https://o160250.ingest.sentry.io);  
> img-src ‘self’ [https://sandbox.web.squarecdn.com](https://sandbox.web.squarecdn.com);

On the square.js line `document.head.appendChild(r)),`

I get a  
` Applying inline style violates the following Content Security Policy directive 'style-src-elem 'self'``https://sandbox.web.squarecdn.com``https://square-fonts-production-f.squarecdn.com`` ``https://d1g145x70srn7h.cloudfront.net``'. Either the 'unsafe-inline' keyword, a hash ('sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='),`

When I add the hash (ending in SuFu=) to my style-src-elem that error disappears.

However trying that approach doesn’t work for r.innerHTML = Rh(e, Jh(t))

That produces

```auto
Applying inline style violates the following Content Security Policy directive 'style-src-elem 'self' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' https://sandbox.web.squarecdn.com https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net'. Either the 'unsafe-inline' keyword, a hash ('sha256-5AjWgndEpRbacB86f2mPOgtBWjcgjFl/hosxZZUABgE='), 

```

I tried with the hash ending with ABgE=, but it seems to change on each page load? I added about 8 hashes which showed up on page load but that never seem to help. The hashes are different on each load. I can’t use ‘unsafe-inline’ because I have a hash for the first error in the source list and it’s ignored.

I can make both go away with unsafe-inline but there has to be a better way.

It’s a payment app. I shouldn’t be asked to reduce the security on my payment page.

The second error I get is

> Loading the font ‘[https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Regular.woff2](https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Regular.woff2)’ violates the following Content Security Policy directive: “font-src [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com) [https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/](https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/) ‘report-sample’”. The action has been blocked.

There are 8 occurrences of this error despite having the following in my policy.

> [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com)
> 
> [https://d1g145x70srn7h.cloudfront.net](https://d1g145x70srn7h.cloudfront.net)
> 
> [https://cash-f.squarecdn.com](https://cash-f.squarecdn.com)

I have also tried to clear those by adding `data:` to font-src

`font-src ‘self’ data: ``https://cash-f.squarecdn.com`` etc`

But that doesn’t work.

What I really don’t understand here is that the error message is saying

violates the following Content Security Policy directive: “font-src [https://square-fonts-production-f.squarecdn.com](https://square-fonts-production-f.squarecdn.com) [https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/](https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/) ‘report-sample’”

But my policy for font-src is

```auto
font-src 'self' https://cash-f.squarecdn.com https://fonts.googleapis.com https://fonts.gstatic.com data: https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/;

```

The csp policy in the error -isn’t- mine? It’s erroring on the `<!doctype html>` line in s`ingle-card-element-iframe.html`

So does that file have some CSP set on the square end? If that’s the case, I’d guess this is why adding `data:` had no effect.

I can’t get the font issue to go away at all

So how do I fix these issues.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [April 24, 2026, 5:56pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/2 "2026-04-24T17:56:38Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Troubleshoot In-App Payments SDK Problems](https://developer.squareup.com/docs/in-app-payments-sdk/troubleshooting)**
>
> Troubleshoot problems with the Square In-App Payments SDK.

> **[Square Sandbox](https://developer.squareup.com/docs/devtools/sandbox/overview)**
>
> An overview of the Square Sandbox, which can be used to simulate orders, invoices, payments, and transactions in a test environment.

> **Additional Documentation**
>
> [Brand and Images](https://developer.squareup.com/docs/app-marketplace/listing-best-practices/brand-and-images)  
> [In-App Payment Solutions](https://developer.squareup.com/docs/in-app-payments)  
> [Sandbox Payments](https://developer.squareup.com/docs/devtools/sandbox/payments)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![JayB](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JayB](https://developer.squareup.com/forums/u/JayB)\
**Post date:** [April 24, 2026, 6:12pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/3 "2026-04-24T18:12:08Z")

</div>

this is not helpful or an answer

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [April 27, 2026, 8:00pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/4 "2026-04-27T20:00:09Z")

</div>

Hey @JayB! Can you provide some more context into your setup here? I’m assuming that you’re using the Web Payments SDK, although I wouldn’t expect you to be running into CSP issues with the default setup. If you spin up the [quickstart app](https://developer.squareup.com/docs/web-payments/quickstart), do the same errors persist in that environment?

---

<div class="post-metadata">

**Author:** ![lavid](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lavid](https://developer.squareup.com/forums/u/lavid)\
**Post date:** [April 28, 2026, 10:33pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/5 "2026-04-28T22:33:35Z")

</div>

A quick start app in development doesn’t see these errors, but a production server with hardened CSP headers will. I asked this same question a few weeks ago and it seems like no one is taking the time to actually read or understand the question: what is the full set of hosts that square relies on for the payment widget?

---

<div class="post-metadata">

**Author:** ![josh-square](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@josh-square](https://developer.squareup.com/forums/u/josh-square)\
**Post date:** [April 29, 2026, 9:12pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/6 "2026-04-29T21:12:37Z")

</div>

@lavid I would not recommend implementing server security that’s dependent on specific hosts used by Square. The Web Payments SDK was not developed with the expectation that developers would be building around specific host domains, so it’s possible for them to change without notice.

---

<div class="post-metadata">

**Author:** ![lavid](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lavid](https://developer.squareup.com/forums/u/lavid)\
**Post date:** [April 29, 2026, 10:38pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/7 "2026-04-29T22:38:55Z")

</div>

Right, and by not publishing that, consumers of the square web payment SDK cannot reliably implement CSP or CORS policies on their websites.

---

<div class="post-metadata">

**Author:** ![mhcwebdesign](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@mhcwebdesign](https://developer.squareup.com/forums/u/mhcwebdesign)\
**Post date:** [May 1, 2026, 4:25pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/8 "2026-05-01T16:25:59Z")

</div>

josh-square: The need to specify a cumbersome CSP for the iframe in the first place is not the way to go. This feature is poorly documented by the squareup developer docs and needs to be re-addressed! It took us hours to define, via trial and error runs, when we developed a new Square payment extension for OpenCart. It was a lot easier when using your quick\_pay which doesn’t rely on iframe. Surely there has to be a better way forward.

Below is what we have for our CSP:

```auto
default-src 'self';
script-src 'self' https://js.squareup.com https://js.squareupsandbox.com https://web.squarecdn.com https://sandbox.web.squarecdn.com 'unsafe-inline' 'unsafe-eval';
style-src 'self' https://js.squareup.com https://js.squareupsandbox.com https://web.squarecdn.com https://sandbox.web.squarecdn.com https://fonts.googleapis.com 'unsafe-inline';
font-src 'self' https://fonts.gstatic.com https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net;
img-src 'self' data: https://js.squareup.com https://js.squareupsandbox.com https://web.squarecdn.com https://sandbox.web.squarecdn.com;
frame-src 'self' https://js.squareup.com https://js.squareupsandbox.com https://web.squarecdn.com https://sandbox.web.squarecdn.com https://connect.squareup.com https://connect.squareupsandbox.com https://api.squareupsandbox.com https://api.squareup.com;
connect-src 'self' https://connect.squareup.com https://connect.squareupsandbox.com https://pci-connect.squareup.com https://pci-connect.squareupsandbox.com;
base-uri 'self';
form-action 'self' https://api.squareupsandbox.com https://api.squareup.com;

```

---

<div class="post-metadata">

**Author:** ![mhcwebdesign](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@mhcwebdesign](https://developer.squareup.com/forums/u/mhcwebdesign)\
**Post date:** [May 8, 2026, 9:28am UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/9 "2026-05-08T09:28:27Z")

</div>

@josh-square : Any update yet as to when this issue will be addressed and solved?

---

<div class="post-metadata">

**Author:** ![JayB](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JayB](https://developer.squareup.com/forums/u/JayB)\
**Post date:** [May 27, 2026, 5:16pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/10 "2026-05-27T17:16:16Z")

</div>

Have been away from this on another project.

As stated, I’m using the iframe Web Pay SDK (unless you’ve got some other iframe thing)

I’m debugging this in Sandbox and the errors listed above exist in both chrome & firefox.

I don’t know much else to say. I outlined as much detail as I could in the OP.

Either the ‘unsafe-inline’ keyword, a hash (‘sha256-b6eYvLwBjP+2SOqzkrJdtWI/qZc0COwp9aM4rmeWP+I=’), or a nonce (‘nonce-…’) is required to enable inline execution. The action has been blocked.

The error occurs in this section.

```auto
 function Mh(e, t) {
        var n = function(e) {
            return "".concat("sq-single-card-custom-styles", "-").concat(e)
        }(t)
          , r = document.getElementById(n);
        null === r && ((r = document.createElement("style")).id = n,
        document.head.appendChild(r)),
        r.innerHTML = vh(e, xh(t)) <ERRORS HERE

```

The suggestion by devtools to use the sha256 would work except that it changes on every page load so it can’t be used for CSP. (changes in both FF & GC so not browser issue)

Why would the sha256 change? Makes it useless.

And I tried adding a nonce to the script source for square.js but that doesn’t work either. Note that square.js works fine because I’ve got the src listed in script-src but the script is applying an inline style which is causing the error. afaik.

The font loading issue on single-card-element-iframe.html still causes 8 errors. No combination of font-src, even undocumented ones seen in forums, make any difference.

While the form still works, it looks terrible because the formatting and fonts in the iFrame are not allowed due to the CSP errors.

And as I noted in the OP using unsafe-inline is not an option.

Might as well not have a CSP at all if that’s required.

EDIT: OK something weird happening. All plugins are disabled, happens in FF & GC in regular & incognito mode.

I completely turned off my CSP (double checked at [Csper: Content Security Policy made easy](https://csper.io/evaluator) which gives “no policies found at URL”), disabled X\_Frame-Options in Apache (and restarted the server) and I’m -still- getting the font error which points to single-card-element-iframe.html

That leads me to believe that the CSP error is actually bubbling up from the iFrame and is actually an issue with the single-card-element-iframe.html page ie: the CSP is broken on the Square side…

---

<div class="post-metadata">

**Author:** ![ragingrei](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@ragingrei](https://developer.squareup.com/forums/u/ragingrei)\
**Post date:** [August 25, 2026, 8:27pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/11 "2026-08-25T20:27:09Z")

</div>

@josh-square I’m getting the same error. Has this been looked at at all?

---

<div class="post-metadata">

**Author:** ![zacstlouis](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@zacstlouis](https://developer.squareup.com/forums/u/zacstlouis)\
**Post date:** [October 28, 2026, 4:53pm UTC](https://developer.squareup.com/forums/t/securely-fixing-csp-errors-in-iframe-widget/25907/12 "2026-10-28T16:53:00Z")

</div>

The documentation for web payments sdk explicitly requires `unsafe-inline` [Add a Content Security Policy](https://developer.squareup.com/docs/web-payments/content-security-policy)

If you have specific CSP security needs for your whole site, you may only relax the policy on pages you load the sdk on instead of your whole site.
