Skip to content

Instantly share code, notes, and snippets.

@nightcoder26
Created October 18, 2025 14:30
Show Gist options
  • Select an option

  • Save nightcoder26/c44a325dc62107aa3d99302cc6f2f561 to your computer and use it in GitHub Desktop.

Select an option

Save nightcoder26/c44a325dc62107aa3d99302cc6f2f561 to your computer and use it in GitHub Desktop.
diff between regular js and react's jsx while handling injections

Regular html against injections

  <div id="hello">
  <script>
  const inp = "<img src='x' onerror ='alert(\"whoops, hacked!\")'>"
  document.getElementById("hello").innerHTML =  inp;
  </script>
  </div>

This executes the code, and pops up an alert.

const inp = "<img src='x' onerror='alert(\"whoops, hacked\")'>";
return <div>{inp}</div>;

This only renders the text, unlike regular js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment