Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
xss prevention with innerHtml and quotes

I am trying to implement rule 1 in the OWASP XSS prevention cheat sheet. Rule 1 states the following characters should be encoded before inserting them into the body of a <div>:

 & --> &amp;
 < --> &lt;
 > --> &gt;
 " --> &quot;
 ' --> &#x27;

My goal is to insert the encoded characters into the DOM and have them render as their non encoded values. However this does not seem to be possible, with quotes.

When you put either &quot; or &#x27; into the innerHTML of a div, the browser converts it back to " or '.

document.getElementById("encodingNotWorking").innerHTML = "&amp; &gt; &lt; &quot;  &#x27; &#39; &#34;"

let domData = document.getElementById("encodingNotWorking").innerHTML;

document.getElementById("actualCharacters").innerText = domData;
Encoded quote characters:
<div id = "encodingNotWorking">
</div>

Characters in the dom:
<div id = "actualCharacters">
</div>

(JSFiddle)

How can I put the encoded entities (quotes) into the DOM, have them render as their non encoded values, and verify the encoded entities are actually in the DOM?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!