kerryb
Working content security policy for Phoenix channels?
Hi,
I use sobelow to highlight potential security issues, and the latest version has started warning if no content-security-policy header is set. I fixed that by adding a custom header:
@csp "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
pipeline :browser do
# ...
plug :put_secure_browser_headers, %{"content-security-policy" => @csp}
# ...
However, this has stopped channels from working. I’ve tried adding various versions of ws://localhost:4000 and the like, but with no success.
Does anyone have a working CSP header for use with channels?
For bonus points, what’s the best way to get the hostname to use in the policy, assuming it needs to be different in production? I could just set a config value in the environment, but is it already available somewhere?
Thanks!
Kerry
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










Most Liked
iautom8things
Just wanted to comment on this, if someone else stumbles across this thread looking for help on fixing sobelow warning about config.CSP even though you’re setting it:
This is referring to this:
You can obviously set headers in different places, so
sobelowis just looking that if you have a pipeline that callsplug :put_secure_browser_headersin your Router, that you also include a map with%{"Content-Security-Policy" => "..."}so it should look like this:kerryb
Thanks! The root of my problem was putting the
ws://URI in quotes, but thestruct_urlthing was really helpful too. FWIW I ended up with this:ryh
You can pull this information from the conn. There may be a better way to do this… for example, there is no check to see if the endpoint is/should be wss.
Have you tried
connect-src? Apparently you must define it for each scheme you use. More information here.Here’s what it might look like:
I tried testing this, but I can’t tell if it works or not.
Last Post!
pdgonzalez872
@iautom8things thanks for adding your reply! If one were to use the map like you suggested, what would folks suggest the contents to be?
When it comes to security I always defer to public and discussed solutions, since incorrect in-house solutions are usually the ones that end up failing and causing vulnerabilities.
Thanks for discussing these things in public, the community always benefits from these discussions.
More info on why how an incorrect implementation can bite you hard: https://www.netsparker.com/blog/web-security/negative-impact-incorrect-csp-implementations/
Edit: I created this issue: Question about how to solve error: `Config.CSP: Missing Content-Security-Policy - High Confidence` · Issue #61 · nccgroup/sobelow · GitHub