-
Notifications
You must be signed in to change notification settings - Fork 2
[FIX] XSS validating context and encoding HTML #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JQuery.parseHTML()
is not a good mitigation for XSS vulnerabilities, it's bypassable. The fix also doesn't seem well fit in the codebase, you rewrote the parseJSON
function to throw a console error which initially just returned a new window.
Good approach tho, without having a PoC! 👏
📚 References:
Hi @mufeedvh 😄
A different solution was using I checked if the fix was broken also making a function like this: function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
} and evaluating the passed
Let me know if the part regarding Cheers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mufeedvh - just to confirm, are you happy with this fix? |
Attaching reference (jquery-form#580)! 🍰 @kevindb - we will look to open this pull request now! |
Congratulations Mik317 - your fix has been selected! 🎉 Thanks for being part of the community & helping secure the world's open source code. |
📊 Metadata *
Please enter the direct URL for this bounty on huntr.dev. This is compulsory and will help us process your bounty submission quicker.
Bounty URL: https://www.huntr.dev/bounties/1-npm-form
⚙️ Description *
The
form
library suffered of aXSS
issue, which was caused by 2 minor issues inside thecode
, which made possible the usage ofeval
onunsanitized values
(inside the "override" ofparseJSON
) andhtml parsing
on aunsanitized AJAX response
.💻 Technical Description *
The 2 issues have been fixed in the following way:
The
eval
inside theparseJSON
function has been removed, while it's been added aerror
which arises when the default$.parseJSON
function (onjquery
) isn't declared (anyone with good intentions would simply add thejquery
script on the page and all works correctly again).The
)
unsanitized AJAX response
was previously passed toparseHTML
without any check, making possible inject additionalHTML
. I used a peculiarity ofjquery
to translate theHTML
nodes evaluated intotext nodes
, which are equal toHTML encoded entities
(can be verified seeing this:🐛 Proof of Concept (PoC) *
No PoC was provided, so I worked mostly theoretically on the issue/lines identified by the 2 issues in the
original repo
🔥 Proof of Fix (PoF) *
Theoretical fix 😄
👍 User Acceptance Testing (UAT)
Can't be sure of this but seems all OK (nodes are still nodes of different type and a function is null --> arises exception due to a function undefined)