GithubHelp home page GithubHelp logo

Question regarding DOMPurify ADD_TAGS is not allowing <script> tag about dompurify HOT 7 CLOSED

yam4office avatar yam4office commented on July 24, 2024
Question regarding DOMPurify ADD_TAGS is not allowing

Comments (7)

realansgar avatar realansgar commented on July 24, 2024 1

\x3c is the hex encoded < character. So the string actually contains <script>, it is just displayed differently by the Chrome console.

Today I learned: The Chrome console does this deliberately and only in very specific instances to enable devs to copy paste stuff from the console directly into an inline script in their HTML file without accidently breaking out of it (or inserting a comment).

from dompurify.

cure53 avatar cure53 commented on July 24, 2024

Heya, try to use the FORCE_BODY: true as config option, that should do the trick 🙂

from dompurify.

yam4office avatar yam4office commented on July 24, 2024

I tried both

DOMPurify.sanitize('<script>a</script>',{ADD_TAGS:['script']},{FORCE_BODY: true})
and

DOMPurify.sanitize('<script>a</script>',{FORCE_BODY: true})
they gave empty string as result, added screenshot from demo page below:

image

from dompurify.

realansgar avatar realansgar commented on July 24, 2024

DOMPurify.sanitize('<script>a</script>',{ADD_TAGS:['script']},{FORCE_BODY: true})

DOMPurify.sanitize takes a single config object with all options, not multiple objects.

DOMPurify.sanitize('<script>a</script>',{ADD_TAGS:['script'], FORCE_BODY: true}) should work instead.

from dompurify.

cure53 avatar cure53 commented on July 24, 2024

Correct @realansgar , thanks 😅

from dompurify.

yam4office avatar yam4office commented on July 24, 2024

It gave the output as
\x3Cscript>a\x3C/script>
is that expected?

attached screenshot
image

from dompurify.

cure53 avatar cure53 commented on July 24, 2024

Nope, this is what the result looks like:

DOMPurify.sanitize('<script>a</script>',{ADD_TAGS:['script'], FORCE_BODY: true})
//  "<script>a</script>" 

from dompurify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.