arnoudkooi / ServiceNow-Utils

Browser Extension to enhance experience and productivity in ServiceNow
https://arnoudkooi.com
249 stars 117 forks source link

"javascript:" slash commands on popped out pages (not in gsft_main iframe) are being mangled by DOMPurify.sanitize() #503

Closed codaroma closed 5 months ago

codaroma commented 5 months ago

Can you try this custom slash command? (it is a simplified example) in a popped out page (not in gsft_main iframe).

Command: test URL: javascript:alert("<test")

When saved it appears in the slash command list as test javascript:alert("

And when you execute it nothing happens and you get errors in the developer tools console. Seems to be the same in both chrome and firefox.

codaroma commented 5 months ago

Looks like it is the call to DOMPurify.sanitize(targeturl) that is mangling the code. image I don't think DOMPurify.sanitize() is designed to be used on javascript code.

codaroma commented 5 months ago

For example URL: javascript:alert("<>&") is converted to javascript:alert("&lt;&gt;&amp;")

codaroma commented 5 months ago

I am trying to create a javascript: slash command that contains a regular expression and DOMPurify.sanitize() is completely mangling it.

codaroma commented 5 months ago

The code path for executing custom "javascript:" slash commands for pages inside the gsft_main iframe and pages that are outside the gsft_main iframe are different. The code that executes "javascript:" slash commands when the page is inside the gsft_main iframe is as follows... image but when the page is not inside the gsft_main iframe the code that executes "javascript:" slash commands is this... image One does a DOMPurify.sanitize() on the targeturl variable and the other does not, which leads to different behaviours. The code path that uses DOMPurify.sanitize() breaks the code in the custom command.

arnoudkooi commented 5 months ago

As there is no external way to manipulate this value, I'll remove the sanitize

codaroma commented 5 months ago

Thanks for fixing the execution is of javascript: URLs in popped out pages. Just in case you missed it the display in the slash command list is still not showing correctly. image

arnoudkooi commented 5 months ago

Is it ok now?

codaroma commented 5 months ago

Yes, many thanks