-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JavaScript: Learn that receivers of DOM event handlers are themselves DOM elements. #5262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript: Learn that receivers of DOM event handlers are themselves DOM elements. #5262
Conversation
This was found by TSM 🎉 (/cc @garbervetsky) |
@@ -0,0 +1,3 @@ | |||
document.getElementById('my-id').onclick = function() { | |||
this.parentNode.innerHTML = '<h2><a href="' + location.href + '">A link</a></h2>'; // NOT OK |
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.
I'm not sure how exploitable this code pattern would be, considering that location.href
is URL-encoded, but of course that's nothing to do with this PR.
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.
I recall there was an issue with IE not encoding the URL when redirected via a Location
header, so I'm fine with flagging it.
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.
And maybe add a comment about not using getABoundFunctionValue
exactly because bound functions will tend to have a different receiver anyway.
or | ||
// A receiver node of an event handler on a DOM node | ||
exists(string handler | handler.matches("on%") | | ||
this = domValueRef().getAPropertySource(handler).(DataFlow::FunctionNode).getReceiver() |
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.
Could we support addEventListener
here?
@@ -0,0 +1,3 @@ | |||
document.getElementById('my-id').onclick = function() { | |||
this.parentNode.innerHTML = '<h2><a href="' + location.href + '">A link</a></h2>'; // NOT OK |
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.
I recall there was an issue with IE not encoding the URL when redirected via a Location
header, so I'm fine with flagging it.
Thanks, @asgerf! Comments addressed and change note added. |
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.
LGTM. Hope the evaluation works out
It did (internal link). Sorry for the delay, and many thanks to @erik-krogh for helping with finally getting the evaluation done! |
cf https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#in_an_inline_event_handler