-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Dangerously set inner HTML in Head #17894
Comments
Try: function Layout({ children }) {
return (
<>
<Head>
<script dangerouslySetInnerHTML={{ __html: 'console.log(\'Hello, World!\')' }} />
</Head>
{children}
</>
);
} |
@balazsorban44 this works, however, the idea is to allow my users to submit custom HTML they'd like added to |
I'm no expert on the topic, but I am not sure allowing your users to modify their html is a secure 🔐 /good idea, it's not a coincidence it's called dangerously set HTML. It's vulnerable enough if it comes from a secure place, getting it from users without sanitisation of some sort could be dangerous. (again, no expert though, can be wrong, maybe you know what you are doing) Do you have a proper use case? Wouldn't Google Tag Manager work to add extra tags dynamically in the head? |
My use case is a B2B SaaS help center service where customers can add their own analytics tags and SEO in their sites. I've seen it done a few other times, Google Tag Manager works but it's a hassle as a customer to have to set that up just to add an analytics tool to your help center. |
#8478 (comment) refers to _document.js. It's not supported for |
This comment has been minimized.
This comment has been minimized.
https://www.npmjs.com/package/html-react-parser |
@VitamineC: thanks for your idea - it works, but unnecessarily increases bundle size. I see that this is not a bug but would also vote for adding this as a feature. The |
@styxlab, I completly agree with you. It's just workaround for fix this issue. |
There is an interesting react rfc so you might be able to do
That's something for the future! |
HI Do you add it on _document.js ? |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Dangerously setting inner HTML does not work directly on the
<Head />
tag as described in #8478 (comment). For example:Are there any other ways of doing this? Or am I doing something wrong here?
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
The console should show
Hello, World!
.System information
Additional context
I cannot use
_document.js
.The text was updated successfully, but these errors were encountered: