Security nonce: <link rel="stylesheet"> and webpack nonce #6374
-
|
Hey Rsbuild team, First, thanks for the excellent work on Rsbuild. It's a really pleasant tool to work with (plus it's super fast 🚀). I have a couple of questions about CSP nonce implementation that I'm hoping you can help with:
index.html <script type="text/javascript" nonce="CSP_NONCE_PLACEHOLDER">
window.webpackNonce = "CSP_NONCE_PLACEHOLDER";
</script>entry.js if (window.webpackNonce) {
__webpack_nonce__ = window.webpackNonce;
}This would allow me to only replace the placeholder in the html file, server-side. Would appreciate any insights on how to handle this, or if there are plans to address nonce support in future releases. |
Beta Was this translation helpful? Give feedback.
Answered by
chenjiahan
Oct 18, 2025
Replies: 1 comment 1 reply
-
|
Thanks for the detailed explanation and raise, a few thoughts:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
auloin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the detailed explanation and raise, a few thoughts:
nonceinto<link rel="stylesheet">. From what I understand,nonceis used for inline scripts and styles, see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce#description2 For
webpack_nonce, your approach is valid — settingwindow.webpackNoncein the HTML and then assigning__webpack_nonce__in entry is a good workaround.