Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Update 2016: There is now a <a href="https://github.com/google/closure-library/blob/master/closure/goog/html/sanitizer/htmlsanitizer.js" rel="noreferrer">Google Closure</a> package based on the Caja sanitizer.</p> <p>It has a cleaner API, was rewritten to take into account APIs available on modern browsers, and interacts better with Closure Compiler.</p> <hr> <p>Shameless plug: see <a href="https://github.com/google/caja/blob/master/src/com/google/caja/plugin/html-sanitizer.js" rel="noreferrer">caja/plugin/html-sanitizer.js</a> for a client side html sanitizer that has been thoroughly reviewed.</p> <p>It is white-listed, not black-listed, but the whitelists are configurable as per <a href="https://github.com/google/caja/wiki/CajaWhitelists" rel="noreferrer">CajaWhitelists</a></p> <hr> <p>If you want to remove all tags, then do the following:</p> <pre><code>var tagBody = '(?:[^"\'&gt;]|"[^"]*"|\'[^\']*\')*'; var tagOrComment = new RegExp( '&lt;(?:' // Comment body. + '!--(?:(?:-*[^-&gt;])*--+|-?)' // Special "raw text" elements whose content should be elided. + '|script\\b' + tagBody + '&gt;[\\s\\S]*?&lt;/script\\s*' + '|style\\b' + tagBody + '&gt;[\\s\\S]*?&lt;/style\\s*' // Regular name + '|/?[a-z]' + tagBody + ')&gt;', 'gi'); function removeTags(html) { var oldHtml; do { oldHtml = html; html = html.replace(tagOrComment, ''); } while (html !== oldHtml); return html.replace(/&lt;/g, '&amp;lt;'); } </code></pre> <p>People will tell you that you can create an element, and assign <code>innerHTML</code> and then get the <code>innerText</code> or <code>textContent</code>, and then escape entities in that. Do not do that. It is vulnerable to XSS injection since <code>&lt;img src=bogus onerror=alert(1337)&gt;</code> will run the <code>onerror</code> handler even if the node is never attached to the DOM.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload