-
Notifications
You must be signed in to change notification settings - Fork 75
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
Update lasso to add support for CSP nonce #93
Comments
Hey @ppattanayak, thanks for opening an issue. This will require some changes to Lasso.js. At a high-level:
NOTE: Nonce can be retrieved from var res = out.stream;
var req = res.req;
var csp = req.csp;
var nonce = csp.nonce; As soon as I get a chance, I'll try to point you in the right direction so that you can make the appropriate changes to support these new hooks. In the meantime, please try to familiarize yourself with some of the Lasso.js code. Thanks again, for opening the issue! |
@ppattanayak can you please confirm if the nonce is needed on all of the following?: <script type="text/javascript" src="/foo.js" nonce="abc123"></script>
<script type="text/javascript" nonce="abc123">console.log('foo')</script>
<link rel="stylesheet" type="text/css" href="foo.css" nonce="abc123">
<style type="text/css" nonce="abc123">.foo { }</style> Or, is it only needed for inline scripts? Thanks. |
Its needed in second and fourth. Not in first and third. |
Great. Thank you for confirming. So only for inline scripts and inline styles. |
Yes, thats correct. |
Hey @ppattanayak and @tropperstyle, please review the following Pull Request to provide CSP nonce support: #94 |
Getting the following error after running
|
Hey @tropperstyle, can you try the following?:
That should wipe out all caches which can cause problems when switching to a new version of a modules. Please let me konw if that solves your problem. |
@tropperstyle Actually, I am able to reproduce. Let me figure out what went wrong! |
I tried using |
It's not a caching issue. We converted the HTML for the head and body slots to templates and the Marko compiler is not liking the |
Hey @tropperstyle, should be fixed now. Please try again:
Thanks for your help! |
It doesn't seem to be picking up the |
@tropperstyle can you give me a more specific path to try? |
@tropperstyle I tried to reproduce your problem by doing the following: Created a new template: node_modules/foo/foo-template.marko <script lasso-nonce>
Hello foo!
</script> Compiled it using
Compiled output: function create(__helpers) {
var str = __helpers.s,
empty = __helpers.e,
notEmpty = __helpers.ne,
__getNonce = require("lasso/taglib/helper-getNonce"),
attr = __helpers.a;
return function render(data, out) {
out.w('<script' +
attr("nonce", __getNonce(out)) +
'>\n Hello foo!\n</script>');
};
}
(module.exports = require("marko").c(__filename)).c(create); You can see from the following line that everything worked as expected: attr("nonce", __getNonce(out)) Please let me know if there is another way I should try to reproduce. Thanks. |
Doh it was on my end. I was editing a file in |
Looks like this output will also require the |
Why do you say that @tropperstyle? There is no script on that line. However, we will need to update Marko Widgets to not use We use |
Inline styles are banned the same way as inline scripts and inline event handlers. Safari is throwing a CSP report on this line unless I add a |
What world are we living in where inline styles are considered dangerous? :) Ok, I propose we switch to the following:
The |
@tropperstyle @ppattanayak I opened a related issue on the Marko Widgets project to support CSP: marko-js-archive/marko-widgets#115 |
New version published: |
Need to update lasso to support the nonce feature of Content Security Policy 2, for the script tags in the HTML.
Example:
The text was updated successfully, but these errors were encountered: