← Back to context

Comment by ranger_danger

11 days ago

relying on any client-side "security" is probably a bad idea

CSP is there to protect your user’s browser, not your servers. It’s ultimately their credentials that are going to get compromised with an XSS attack.

  • All things considered I think CSP is a good thing, a bit of a nuance for website operators, but it probably helps protect against lot of attack types.

Client side security isn't the issue, but CSP is kind of a shit show. The configuration apparatus is godawful. I think the best way to think of it is if someone turned CSS (yes, the styling language) into a security configuration protocol. It uses the same style of cascading overrides that CSS employs.

What is the alternative when you need to embed third-party JavaScript on your pages? Other than just "not doing that"?

  • If it's available, pull the third party JS in at build time via package manager rather than at runtime via a CDN you don't control.

    NPM isn't perfect but there's typically a substantial delay between the release of a malicious package and that code getting onto your production environment. Unless you're automatically updating every day, there's a good chance someone will discover the problem before it affects you. And you can always scan your upstream dependencies.

    This doesn't work if you're using someone else's CDN. Any change to their content is distributed to all your users immediately.

  • A certificate-based approach for scripts residing on different domains, for example, so you can be sure it hasn't been tampered with.

    A javascript file served from example-a.com should be able to run on example-b.org only if it has been signed with the same TLS key used for example-a.com .

  • Proxy through your own domain? Has its own issues though

    • That is not any more secure if you are just blindly proxying the third party scripts and in fact is worse since it runs in the context of your own domain.

    • Since the third party tag can request anything, this doesn't stop anything and now your domain has an open redirect.

Most of it is server to server now with server side tagging. 3rd party cookies are now 1st party and beacon call is server to server.