Skip to content

JavaScript: Fix DomMethodCallExpr.interpretsArgumentsAsHTML.#1835

Merged
semmle-qlci merged 2 commits intogithub:masterfrom
xiemaisi:js/dom-fixes
Aug 30, 2019
Merged

JavaScript: Fix DomMethodCallExpr.interpretsArgumentsAsHTML.#1835
semmle-qlci merged 2 commits intogithub:masterfrom
xiemaisi:js/dom-fixes

Conversation

@xiemaisi
Copy link

The first argument to setAttribute is the attribute name, which is generally less sensitive than the second one, so I've changed it. Similar comments apply to the other changes.

I've run a dist-compare (internal link) on nightly.slugs. The results are a bit mixed: while the new results on Lucifier look good, the ones on gatsby are false positives. They are, however, in test code, so wouldn't be displayed on LGTM.

I think a proper fix for these false positives would involve flow-labelifying the XSS query.

If we feel uncomfortable with the new results, I'm happy to scrap/postpone this PR.

@xiemaisi xiemaisi added the JS label Aug 28, 2019
@xiemaisi xiemaisi requested a review from a team as a code owner August 28, 2019 11:08
@asger-semmle
Copy link
Contributor

Worth landing IMO.

I think a proper fix for these false positives would involve flow-labelifying the XSS query.

Let's talk about this offline

@ghost
Copy link

ghost commented Aug 28, 2019

How about restricting this to only flagging assignments to a library set of dangerous attribute names (such as "src", "href", "style")? That is what we do for ordinary property assignments such as innerHtml already.

The "data" property is interesting for an exploratory query, as that property often is read later and used unsanitized in an ordinary XSS sink.

@xiemaisi
Copy link
Author

How about restricting this to only flagging assignments to a library set of dangerous attribute names

Good idea in general, although it wouldn't help avoid the false positives in this case; they are all about setting href (to harmless values).

@xiemaisi
Copy link
Author

Updated as suggested.

) and
// restrict to potentially dangerous attributes
exists(string attr | attr = "href" or attr = "src" |
getArgument(argPos-1).getStringValue().toLowerCase() = attr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have isUrlValuedAttribute which seems to do this more generally, although it currently only works if the element type is known. Maybe we could reuse that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting thought. That predicate does rely on knowing what the element type is, though, which in this case we don't. (I'll definitely add action and formaction here, though.)

Copy link
Contributor

@asger-semmle asger-semmle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@semmle-qlci semmle-qlci merged commit a97aefe into github:master Aug 30, 2019
@xiemaisi xiemaisi deleted the js/dom-fixes branch September 12, 2019 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants