paulanthonywilson
I had a bit of a mini-adventure following Sobelow’s advice on adding a CSP to a Phoenix App. If you want to follow along, or want to add a CSP to your own Phoenix App, then I wrote all about it here.
Posted via Devtalk (see this thread for details).
Trending in Blog Posts
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
Hey everyone! :waving_hand:
I’ve published Part 7 of the Building Distributed Systems in Elixir series, where we build core distributed ...
New
An educational side project in Elixir, Phoenix, and Tauri. I share what I learned while wiring Automerge into the BEAM, including how I s...
New
So, instead of wasting my afternoon arguing with anonymous handles on X, I turned to my trusty, soulless assistant and said: “Listen, ple...
New
Process labels are useful for visualization and debugging. Here’s why you should use them.
New
New article: Elixir Project Structure — From mix new to a Growing Codebase
I’ve published a new article in my Elixir learning series on d...
New
What happens if you design tools for LLMs instead of letting LLM use human tools ?
Wrote a blog on why and what that enables.
As I see ...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
corvus
“When it comes to CSP, just about any policy is better than none” - Sobelow’s documentation
There’s a 2016 paper out of Google that found most sites CSP policies don’t work, https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45542.pdf
worth reading if you’re interested in the subject
paulanthonywilson
Oh, thanks. I do find security things both fascinating and scary; sometimes I teeter on the edge of despairing that it’s all too complicated and one slip will make all the efforts pointless.
On first read I get
'unsafe-inline'is bad. (Alsounsafe-eval). The “unsafe” part is a bit of a hint.egranty
Nice manual! It fills the niche of “how to publish a CSP header in Phoenix”, while for other platforms Node.js, Wordpress, etc there is a lot articles.
It is only more correct to link to the official source Content Security Policy (CSP) - HTTP | MDN, since
content-security-policy.comis an outdated site with incorrect information. For instance the wrongscript-src 'nonce-r@nd0m'is shown right on the main page - the @ character is not allowed in the ‘nonce-value’.The
2016 paper out of Googlerefered below is not actual.In 2016 IE had 30% of the market but did not support CSP. Other browsers, except for Chrome, were supported CSP very poorly too.
Many third party javascript libraries required
'unsafe-inline'and some also required'unsafe-eval'.Popular site engines (CMS) also required rework in their scripts and styles.
Now things changed and Content Security Policy has become a de facto “must have” standard - every browser extension or web app must have it.
Security requirements have increased, Chrome extensions do not allow
'unsafe-inline'at all, Firefox extensions with a policy that use'unsafe-eval'/'unsafe-inline'keywords, allowing loading of external scripts and resources, as well asblob:files, are not allowed for extensions listed onaddons.mozilla.orgdue to major security issues.The situation is somewhat complicated by Safari browser, which is stuck at the CSP2 level.
Nonetheless all serious sites that work with personal data (Twitter, Facebook, Google, …) or money transfers (Paypal, etc.). have a CSP.
In addition to XSS attacks, CSP protects against ads substitution and injecting third-party ads, and prevents users from being tracked on the Internet.
So your article is very relevant for ordinary webmasters as well.
PS: To the principle “When it comes to CSP, just about any policy is better than none” from Sobelow’s documentation, I can add: “safety is never enough”.
paulanthonywilson
Thanks! I’ve updated the post to link only to the MDN documentation.
travisf
Thanks for the fantastic article. It helped me fix a production bug where LiveView was refreshing every 10 or 15 seconds!
glpecile
Hey, great article!
A couple of notes I found when implementing it to my phoenix LiveView webapp that could help to those who want to also implement this.
When compiling the final snippet I got the following warning:
warning: Application.fetch_env!/2 is discouraged in the module body, use Application.compile_env/3 insteadWhere I replaced the fetch env line for:
Also the last snippet where the
"font-src data:;"is added seems to be missing a<>at the end of the line aboveOther than that it seems to be working great and I totally agree that it is best to not ignore advice from security experts!
Edit: typo.
paulanthonywilson
Thanks. This post predates
Compile.env/3and I’ve been meaning to update it.It really should be getting the host at runtime these days, rather than compiling in, as that is by default now set in `runtime.exs.