-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add nonce support #1566
Add nonce support #1566
Conversation
cc0c845
to
3c4ece9
Compare
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.
Looks great!
Could you please resolve a few minor comments? Thanks!
src/components/RedocStandalone.tsx
Outdated
@@ -43,6 +45,10 @@ export class RedocStandalone extends React.PureComponent<RedocStandaloneProps> { | |||
|
|||
const normalizedOpts = new RedocNormalizedOptions(options); | |||
|
|||
if (normalizedOpts.nonce !== undefined) { | |||
__webpack_nonce__ = normalizedOpts.nonce; |
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.
It may crash with ReferenceError
in non-webpack env, e.g. when used by redoc-cli. We should add a check if the __webpack_nonce__
is defined.
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.
I had to use try/catch
because __webpack_nonce__
is initially set to undefined
making disambiguation between variable being declared but not set and not being declared at all very hard.
If you have a better way, I'm open to suggestion.
fe94fe6
to
56f3f46
Compare
@RomanHotsiy Thanks for the review ! I made the requested changes. |
ping @RomanHotsiy |
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
56f3f46
to
8a4ec86
Compare
Redoc is broken if the page where it loads has CSP, in particular
style-src
directives. If inline styles are forbidden by the CSPs, the browser will refuse to load them, and Styled-Components won't work at all.Styled-components already support CSPs by reading a nonce from
__webpack_nonce__
to apply it on every injected style tag. However, there's no way to configure this nonce with Redoc.This is what I added in this PR. The nonce can either be filled in the HTML with a
nonce
attribute (similarly to other HTML elements like script or styles) or provided in the options object.