kerryb
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 working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
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
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
outlog
what @ryh said.. just remember wss in production:)
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:tom-gerken
This was really helpful Kerry, thank you. With respect to the Sobelow warnings, did you just suppress this warning because the plug you wrote covers it? I’m able to use your plug to add a content-security-policy, but it does not pass Sobelow’s test.
kerryb
Yes, I’ve just looked at my sobelow config, and I’m ignoring Config.CSP.
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: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