Skip to content
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

innerHtml and cross-site scripting attacks #40

Open
pat-cki opened this issue Apr 24, 2020 · 1 comment
Open

innerHtml and cross-site scripting attacks #40

pat-cki opened this issue Apr 24, 2020 · 1 comment

Comments

@pat-cki
Copy link

pat-cki commented Apr 24, 2020

Using innerHtml is not the best practice as it can expose your app to cross-site scripting attacks. This is something to be aware of when you will be working on more advanced or professional projects in the future. I recommend you to read this two short articles that explain this issue further:

A safer alternative to innerHTML with vanilla JS
Preventing cross-site scripting attacks when using innerHTML in vanilla JavaScript

@oliverjam
Copy link

I have to take credit for this one, my workshop told them to do this 🙃 https://github.com/oliverjam/learn-dom-rendering#innerhtml

You're safe from XSS as long as you don't put user input inside the HTML strings, which as far as I can tell you're not doing here (since you're using createElement to make the dog elements, which are the only place you render user input to the page).

That said Pat is right that you probably won't use innerHTML much on a "real" project as it's safer to just avoid it all together just in case you accidentally allow an XSS vulnerability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants