Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSP support #149

Closed
crkent opened this issue Oct 13, 2022 · 14 comments
Closed

Fix CSP support #149

crkent opened this issue Oct 13, 2022 · 14 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@crkent
Copy link

crkent commented Oct 13, 2022

Code highlighting breaks for applications which set CSPs. This is due to the use of an inline style element to add (Makeup-generated) highlighting.

https://github.com/phenixdigital/phx_live_storybook/blob/a6a8c6beae69fa30f96083acd4cf33b1fc54edea/lib/phx_live_storybook/templates/layout/root.html.heex#L28-L30

To fix this, the simplest solution could be to add support for a nonce parameter from the conn. Happy to submit a pull request for this, if desired.

@cblavier cblavier added the good first issue Good for newcomers label Oct 13, 2022
@cblavier
Copy link
Contributor

Hey Carson, I wasn't really aware of CSP, thanks for raising this issue.
Please open a PR

@cblavier
Copy link
Contributor

👋 @crkent still wanna open a PR on this topic?

@cblavier cblavier closed this as completed Nov 5, 2022
@gaiabeatrice
Copy link
Contributor

Hi @cblavier, congrats on this super cool library, I absolutely love it!

I was wondering if there is a reason this got closed. I am still getting this.

How to replicate

Make sure the :browser pipeline in the router includes CSP headers

  pipeline :browser do
    # other plugs
    plug :put_secure_browser_headers, %{"content-security-policy" => "default-src 'self'"}
  end

The code snippets won't load the syntax highlighting:
Screenshot 2022-12-27 at 11 33 08 AM

@gaiabeatrice
Copy link
Contributor

Just to add more context, this is an issue Phoenix Live Dashboard was having as well, and the following discussion is very interesting to read to find a similar solution.
phoenixframework/phoenix_live_dashboard#183

@cblavier
Copy link
Contributor

cblavier commented Jan 2, 2023

Thanks for your feedback, Beatrice.
I closed the issue because I had no news from @crkent

I will reopen it, and get it fixed!

@cblavier cblavier reopened this Jan 2, 2023
@gaiabeatrice
Copy link
Contributor

Beatrice is my last name, I go by Gaia 😁

Let me know if you need help, I can probably whip up a PR if needed.

@cblavier
Copy link
Contributor

cblavier commented Jan 2, 2023

Sorry about that, Gaia :)
I would gladly take a PR and review it, thanks for proposing.

@cblavier
Copy link
Contributor

cblavier commented Jan 9, 2023

Hey Gaia, still want to open a PR? Need any help?
Let me know!

@gaiabeatrice
Copy link
Contributor

Hi, sorry, I'm having some really busy times this period, I was planning on work on this at the end of this week. If it's too late let me know

@cblavier
Copy link
Contributor

cblavier commented Jan 9, 2023

No that's fine!
I'm still aiming at a 0.5.0 release by the end of the month

@cblavier cblavier closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2023
@Papipo
Copy link

Papipo commented Jul 19, 2023

Why was this closed? I am having this issue in the latest version.

@cblavier
Copy link
Contributor

This was closed by lack of external contribution 🤷‍♂️

I'd be more than happy to receive a PR on the topic, I don't know anything about CSP

@cblavier cblavier reopened this Jul 20, 2023
@gaiabeatrice
Copy link
Contributor

Hi sorry for the enormous and inexcusable delay.

I came back to work on this and I am having some issues with some inline styles. I can still open the PR, so someone more expert on the frontend can maybe help.

@cblavier cblavier self-assigned this Oct 8, 2023
@cblavier
Copy link
Contributor

cblavier commented Oct 8, 2023

Thanks a lot, @gaiabeatrice 🙏🙏🙏
It helped me a lot in understanding what CSP and nonces are.

I also had issues with favicons, but I fixed it by allowing self in the img-src directive in my policy as such:

img-src 'self' 'nonce-#{img_nonce}'

From my understanding, the nonce should have been enough, but anyway, that did the trick.

@cblavier cblavier closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants