-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Send JSON payload within a <script> tag #3461
Conversation
Here's where we're using this improvement: GrapheneOS/discuss.grapheneos.org@0dfc779
|
This is a more readable way to view our Content-Security-Policy setup since GitHub doesn't wrap lines: The remaining improvements would be replacing all the inline CSS and the more difficult step of integrating Trusted Types, ideally by avoiding APIs like innerHTML so that the Trusted Types policy can be enforced as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I would like to move the 2 inline scripts in framework/core/views/frontend/app.blade.php to their own dedicated files, how would the project prefer to deal with that?
That would be better in the long term, but with the way we handle assets with the SPA it won't be straightforward. We might need to add a new frontend definition on the backend to register non-SPA scripts.
'unsafe-inline'
forscript-src
can be replaced with..
You might not be able to get rid of unsafe-inline
just yet depending on the extensions you use and if you allow post formatting.
We have CSP on the roadmap to investigate and come up with a plan, the problem is supporting it with third-party extensions and making it possible with the textformatter library we use which adds inline scripts and styles depending on post content.
But this is a good step forward imo.
BBCode extension tries to use inline / dynamically evaluated JavaScript for both BBCode and Markdown code blocks which will end up breaking. It appears that Markdown doesn't support syntax highlighting when the BBCode extension is disabled and we have it disabled. It looks like this could be resolved by statically including the highlight.js scripts/styles with Flarum with global JavaScript handling applying it to the code blocks instead of code being included inline with each one. This would also avoid the need to depend on fetching highlight.js content from an external CDN. It breaks a bit differently for viewing existing posts and the preview feature because it counts as dynamic code evaluation with how the preview works vs. unsafe inline styles/scripts for viewing existing content. It looks like it would be possible to whitelist it in CSP with how it works for existing content by adding the CDN URLs and the relevant hash for the inline script along with For now, we're fine with how things work since we don't really want BBCode and that happens to disable the syntax highlighting support right now which would break with our Content-Security-Policy. |
For future reference, the dynamically evaluated code is from the live preview events onrender/onupdate. They are declared in data-* attributes directly in the markup, similarly to an inline event. The attribute's content is used to create a The same strategy can be used to avoid I have a live demo online that usually runs the latest version of the code. The current version has a minimal CSP directive that only allows the live preview code and the CDN. Do note that while the hljs-loader script is loaded with SRI, the JavaScript files from Highlight.js CDN are not. |
Changes proposed in this pull request:
Instead of dynamically changing this script every time with the JSON payload, send the JSON payload within a
<script>
tag. This will allow site admins to specify a hash for the 2 inline scripts in this file within their CSP, so they should be able to remove the need forunsafe-inline
.Reviewers should focus on:
I don't really have any concerns, at some point I would like to move the 2 inline scripts in
framework/core/views/frontend/app.blade.php
to their own dedicated files, how would the project prefer to deal with that?Screenshot
N/A
Necessity
Confirmed
composer test
).