Square form fails to initialise - various Network issues

I have implemented the Web Payments SDK. I have everything set up correctly including CSP etc. but customers are regularly seeing the card form fail to initialise

In developer tools under Network I am seeing various blocked resources but it varies by browser.

In Firefox there are multiple NS_ERROR_DOM_NETWORK_ERR for pci-connect.squareup.com but these errors don’t appear in Chrome nor Edge.

In both Chrome and Edge various fonts fail to load for https://web.squarecdn.com/1.84.3/card-element.css

And info-icon.svg fails to load for https://web.squarecdn.com/1.84.3/card-wrapper.css

At this point I’m seriously considering reverting to Stripe because I’m losing sales due to this :frowning:

I have disabled all extensions/blockers etc and tried in private/incognito

Can you verify/paste the contents of your CSP here? Could you also post the exact error message(s)?

You can validate your CSP here to make sure its being loaded appropriately https://csp-evaluator.withgoogle.com/ as well. I tested the documented CSP in my local app in chrome and firefox without issues.

Troubleshooting steps:

  1. Read through this whole doc
    1. There are multiple CSPs depending on the payment platforms you are using (Square, Cash App, Afterpay, etc.
    2. There are different CSPs for the sandbox and production, so make sure you use the right ones
  2. Check browser extensions especially ad blockers/privacy extensions
  3. If nothing works, you could try reproducing the error in our quick start app GitHub - square/web-payments-quickstart: Quickstart for using Square's Web Payments SDK · GitHub
content-security-policy-report-only default-src ‘self’; script-src ‘strict-dynamic’ ‘nonce-nonce6a99de9ac8a1d0-43934545’ ‘self’ https: ‘report-sample’ ‘unsafe-inline’; object-src ‘none’; frame-src ‘self’ https://*.squarecdn.com https://www.paypal.com https://www.google.com https://www.facebook.com https://player.vimeo.com https://www.youtube-nocookie.com; frame-ancestors ‘self’; style-src ‘self’ ‘unsafe-inline’ https://web.squarecdn.com https://sibforms.com; img-src ‘self’ data: https://www.googletagmanager.com https://www.google.com https://….googletagmanager.com https://www.google.com https://www.google.co.uk https://*.google-analytics.com https://*.analytics.google.com https://*.googlesyndication.com https://*.g.doubleclick.net https://ad.doubleclick.net https://www.googleadservices.com https://www.facebook.com https://*.postcoder.com https://www.paypal.com https://*.sibforms.com; base-uri ‘self’; require-trusted-types-for ‘script’; upgrade-insecure-requests; report-to csp-endpoint; report-uri

Sorry realised the above is truncated with a large section missing at the “…”

Firefox reports -

Content-Security-Policy: The page’s settings blocked the loading of a resource (font-src) at https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Regular.woff2 because it violates the following directive: “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/ ‘report-sample’” single-card-element-iframe.html

Content-Security-Policy: The page’s settings blocked the loading of a resource (font-src) at https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Semibold.woff2 because it violates the following directive: “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/ ‘report-sample’” single-card-element-iframe.html

Content-Security-Policy: The page’s settings blocked the loading of a resource (font-src) at https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Regular.woff2 because it violates the following directive: “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/ ‘report-sample’” single-card-element-iframe.html

Content-Security-Policy: The page’s settings blocked the loading of a resource (font-src) at https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Semibold.woff2 because it violates the following directive: “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/ ‘report-sample’”

Chrome reports -

  1. Some resources are blocked because their origin isn’t listed in your site’s Content Security Policy (CSP). Your site’s CSP is allowlist-based, so resources must be listed in the allowlist to be accessed.

    A site’s Content Security Policy is set either via an HTTP header (recommended), or via a meta HTML tag.

    To fix this issue do one of the following:

    • (Recommended) If you’re using an allowlist for 'script-src', consider switching from an allowlist CSP to a strict CSP, because strict CSPs are more robust against XSS. See how to set a strict CSP.
    • Or carefully check that all of the blocked resources are trustworthy; if they are, include their sources in the CSP of your site. :warning:Never add a source you don’t trust to your site’s CSP. If you don’t trust the source, consider hosting resources on your own site instead.
    1. 2 directives
      1.

^I’m not implementing Cash App Pay, just card

I think the font-src errors are due to a CSP policy on the Square side of things, not us.

The Square CSP Docs (yes I did read them fully) say use “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net” - I have that covered with “font-src ‘self’ https://*.squarecdn.com https://d1g145x70srn7h.cloudfront.net” so I think the single-card-element-iframe.html:0 is causing this by specifying “font-src https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net/fonts/sqmarket/ ‘report-sample’” but trying to access https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Semibold.woff2???

Having gone into all the above, in general the form does still load and work despite the CSP errors, BUT

  • there are frequent fails to load the SDK js (my code tries several times if it fails, but this takes time and I can’t see why the fail rate?)
  • there are fails to initialise - or it takes a very long time. The Dom is ready and the card fields available when the initialise is called so it’s not that… (again, my code repeats the request if needed)

Thanks for that! It looks like there are some issues with your CSP

Summary of what to add:

connect-src 'self' https://web.squarecdn.com https://pci-connect.squareup.com https://o160250.ingest.sentry.io;
font-src 'self' https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net;

And add https://web.squarecdn.com to img-src.

Further Explanation

Missing directives:

  1. connect-src is missing entirely. Without it, default-src 'self' applies, blocking all connections to pci-connect.squareup.com and web.squarecdn.com.
    Add the below and any other support payment CSPs from the doc above:
connect-src 'self' https://web.squarecdn.com https://pci-connect.squareup.com;
  1. font-src is missing entirely so it falls back to default-src 'self', blocking the SDK’s fonts. This is why fonts fail in Chrome/Edge.
    Add:
font-src 'self' https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net;

  1. img-src doesn’t include web.squarecdn.com which likely causes the info-icon.svg load failure.
    Add:

https://web.squarecdn.com to the existing img-src.

Potential issues:

  1. script-src uses 'strict-dynamic'. With strict-dynamic, allowlist entries like https: are ignored in supporting browsers. The SDK script at https://web.squarecdn.com/v1/square.js will only load if it’s given the correct nonce attribute, or if it’s dynamically injected by an already-trusted script. Make sure the script tag loading square.js has the matching nonce attribute:

  2. require-trusted-types-for 'script' can interfere with the SDK’s internal DOM manipulation if it uses innerHTML or similar APIs. If you see Trusted Types violations in the console after fixing the above, you may need to add a policy or remove this directive on the payment page.

These look fine:
• frame-src — https://*.squarecdn.com correctly covers the SDK iframe
• style-src — https://web.squarecdn.com and 'unsafe-inline' are both present

Argh SORRY, the CSP I pasted above was copied from the browser dev tools rather than my code, and seems to have been truncated. I appreciate your reply above but the full CSP is as follows, and has always contained the connect-src, font-src, and img-src you’ve suggested I add.

I also removed the require-trusted-types-for 'script' which was suggested by the Google CSP evaluator (that you suggested above) before most of my replies above.

And yes, all calls include the nonce attribute, I’m well aware of that.

Please would you reply again having looked at all my replies, and bearing in mind they are all based on the following CSP rather than the truncated one above (sorry again)

Please take a look at your suggested font-src because the errors I’m getting are due to the CSP within the injected single-card-element-iframe.html:0 which overrides the site CSP (and therefore my CSP can’t solve) and is missing https://cash-f.squarecdn.com for font-src

If you don’t believe me, please load https://web.squarecdn.com/1.84.3/single-card-element-iframe.html in a browser with dev tools running and look at the CSP errors

I can reproduce the the font errors from the square iframe itself, it shouldn’t affect anything payment wise and I don’t see any issues on the rendering either.

  1. Have you checked the exact CSP loaded on your page? Located in the DevTools > Network > Initial page request.
    1. There might be a default CSP applied to the HTML. The browser chooses the stricter of the CSPs loaded on the page.
  2. How is your site being loaded? Do you have access to the parent site or are you trying to embed your payment html in an iframe (i.e., main website window > custom square payment iframe > square card iframe)
    1. You can DM me a link to the page if possible, I can do a quick gander but no promises unfortunately
  3. If all else fails, I highly recommend trying to reproduce with the quick start app. It’s very basic which will help isolate any issues.
    1. GitHub - square/web-payments-quickstart: Quickstart for using Square's Web Payments SDK · GitHub
  1. My CSP definitely includes font-src https://*.squarecdn.com (and this is what is loaded) which would allow https://cash-f.squarecdn.com/static/fonts/cashsans/woff2/CashSans-Regular.woff2 etc BUT the stricter CSP is loaded within the Square iframe injected by the SDK, so those font loads are blocked by your CSP.
    And in any case your recommended font-src ‘self’ https://square-fonts-production-f.squarecdn.com https://d1g145x70srn7h.cloudfront.net; would still block these requests…

This might not affect the rendering, but given that Square insists on the correct CSP, it’s more than a little ironic that it’s not totally correct on your side…

  1. I code and control the website. I’m using the JS Web Payments SDK with PHP. No iframes. I can DM you the link but you’d have to create an order to see the page.

  2. Is there a sample page at a particular URL that I can look at, or do you mean going through all the github stuff?

Sorry for this wild goose chase! I took a look at your site and went through the booking process to check out the payments page. I thought you were getting CSP errors form https://pci-connect.squareup.com/payments/mtx/v2 but they are network errors. Is that what you are seeing?

I re-tested my site on firefox and I get the same network errors. If you inspect the stack trace of the network calls you can see they are metric logging calls and not critical to the load/usage of the card endpoint.

Is anything about the card payment not working? Or does what I said above track?

And the font stuff can be ignored, I’ll ask the devs about it and see if we can’t resolve that on our end.

Hey

Thank you so much for taking the time to do that!

Yes I guessed that was the case re those - I have a lot of programming experience, but am a little bit in the dark with network traffic sorry. I still think it would be good for Square to sort out the CSP font errors, but I understand they aren’t breaking it.

The card payment seems to work in most cases, but I am seeing page reloads where the card form takes some seconds to initialise and populate.

I’ll keep an eye on it as I’ve re-written the logic just now to load the js earlier. Won’t help with slow/failed initialise but we’ll see.

Many thanks

Martin

No problem! I tend to only monitor the console in dev tools and never look at network unless my specific API isn’t working haha.

For the card form load timing all I can say is make sure the script itself is loading from a browser cacheable script source. I couldn’t find its script tag but I also didn’t look too hard. On my local app I eagerly load all of the payment frames at checkout so the delay isn’t noticeable.

@ellismp Our development team should be rolling out updates to resolve the CSP font errors you were seeing.

Thanks for reporting it!