-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[馃悶] nonce is missing on scripts #4411
Comments
mind creating a new PR?! would be very happy to merge it! |
@manucorporat I still have no idea what the flow of qwik-city is. The second one might be sw-prefetch.ts But somehow, this looks correctly implemented: export const ServiceWorkerRegister = (props: { nonce?: string }) =>
jsx('script', { dangerouslySetInnerHTML: swRegister, nonce: props.nonce }); PS: In the next weeks I will read the whole project through, would be awesome to contribute a bit in code and not only in words ;) |
@tzdesign can you share a link to a repository or stackblitz to reproduce the issue and i will try and help |
@DustinJSilk Stackblitz fails somehow. These guys seem to be having trouble. See https://github.com/the-zimmermann/csp-nonce-issue I just added the plugin the scripts are reported and one odd thing a temporary script or smt? |
I see you havent passed the nonce to the ServiceWorkerRegister. Try updating your root.tsx file to include this: const nonce = useServerData<string | undefined>('nonce')
return <QwikCityProvider>
<head>
<meta charSet="utf-8" />
<link rel="manifest" href="/manifest.json" />
<RouterHead />
</head>
<body lang="en">
<RouterOutlet />
<ServiceWorkerRegister nonce={nonce} />
</body>
</QwikCityProvider> |
@DustinJSilk oh, I did not know that. Isn't there a way to do this under the hood? Thanks for your help. |
@DustinJSilk if you do this in my repository do you still see the issue pointing to a missing script (closing <style/>)? How do you deal with This document requires 'TrustedScriptURL' assignment. ? |
Feel free to submit a PR with documentation. I don't use |
@DustinJSilk I've removed require-trusted-types-for and you're right about that, but would you please check again? There are still bugs like when there are some temporary scripts, if you follow the link in dev-tools, you end up at the end of a style tag and there are no script tags anymore. @jordanw66 thanks for clarifying |
@tzdesign i dont have much capacity right now, have you checked if this issue is a regression yet? Try installing qwik/qwik-city v1.0.0. If it works, it would help to know which version of qwik it stopped working. |
@DustinJSilk I'm pretty busy too, but I checked it out. v1.0.0 works fine, not a single report in the console. I added a page to the docs in this pr #4440. |
Nice PR and thanks for checking v1! I鈥檒l try dig into it soon as well as it鈥檒l probably block my next production release |
@DustinJSilk looks like version 1.1 is already having this issue. I think it's the new RouterOutlet by @manucorporat with a plain script. Would it be save to add /**
* @public
*/
export const RouterOutlet = component$(() => {
_jsxBranch();
const nonce = useServerData<string | undefined>('nonce');
const { value } = useContext(ContentInternalContext);
if (value && value.length > 0) {
const contentsLen = value.length;
let cmp: JSXNode | null = null;
for (let i = contentsLen - 1; i >= 0; i--) {
cmp = jsx(value[i].default, {
children: cmp,
});
}
return (
<>
{cmp}
<script dangerouslySetInnerHTML={popStateScript} nonce={nonce}></script>
</>
);
}
return SkipRender;
}); If yes let me know, I can create another PR |
Yes that looks like it would work. Have you managed to test if it solves the problem in your repo? |
@DustinJSilk In my pr I changed the router-outlet, but there is a discussion if it should be changed to a prop instead of useServerData. Let's see what Manu thinks as he has rewritten this file. |
Found it under the docs pr |
Which component is affected?
Qwik City (routing)
Describe the bug
I'm not sure what exactly this code is. It looks like something in qwik city.
These two tags are rendered in preview without a nonce.
Reproduction
https://github.com/the-zimmermann/csp-nonce-issue
Steps to reproduce
Just run preview
Run a qwik app with a plugin middleware:
plugin@csp.ts
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: