Skip to content

Conversation

@asger-semmle
Copy link
Contributor

Adds isThirdPartyControllable() predicate to RemoteFlowSource for flow sources that can be controlled by the attacker during CSRF.

ReflectedXSS and ServerSideUrlRedirect have been updated to use this. This eliminates some false positives.

The CorsMisconfiguration query is a bit of a conundrum. It is certainly in the CSRF category, but is different from the others in that the tracks values that may refer to a foreign URL. Most importantly, this includes the Origin header, which is may refer to a malicious web site, but is not otherwise directly controlled by the attacker. I see three options for how to approach this:

  1. Change CORS to only use third-party controllable flow sources, with the special addition of the Origin header, and maybe the Referer header.
  2. Change isThirdPartyControllable() to include Origin and Referer headers. Technically you could have a reflected XSS through the referer header, and a server-side URL redirect to the referer could cause information leak if a secret session/auth token is appended in the URL.
  3. Leave the CORS query as it is.

So far this PR just uses option 3, but I'd like to hear your opinion on this. I haven't seen any concrete results that could motivate one choice over another.

Use it in ReflectedXSS and ServerSideURrlRedirect
@asger-semmle asger-semmle requested a review from a team as a code owner October 3, 2018 09:43
Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

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

I agree with the overall goal of this PR, but I'm wondering whether we should perhaps go about it slightly differently as suggested in the comments.

* request can be controlled by a third party, that is, an actor other than the one
* sending the request.
*
* Any web site can redirect the visitor's browser to any other domain, and in doing so control
Copy link

Choose a reason for hiding this comment

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

I don't understand this explanation, particularly the bit beginning with "and in doing so". Why is it important what the web site controls? Aren't we more interested in what data the remote user/attacker controls?

Copy link
Contributor Author

@asger-semmle asger-semmle Oct 3, 2018

Choose a reason for hiding this comment

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

The web site is the attacker here. Would the following change clarify things?

A malicious web site can redirect the visitor's browser to any other domain [...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal of the paragraph is to explain why a user might sent a request with data he doesn't control, and why it's not okay to just blame for user for sending stupid requests that compromise his account.

Copy link

Choose a reason for hiding this comment

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

Yes, I think that would be clearer.

}

/**
* Holds if this flow source comes from an incoming request, and this part of the
Copy link

Choose a reason for hiding this comment

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

This sounds too special-case to put it on a fairly general class like RemoteFlowSource. Is there a more general way to describe this scenario independent of the specifics of HTTP requests? Or should we perhaps only have this predicate on RequestInputAccess and specialise the sources of ReflectedXSS and ServerSideUrlRedirect to be request input accesses? (I don't think any of the other remote flow sources are relevant for those two queries, but it's of course worth checking.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I wanted to describe it more generally as something like:

Holds if data from this source may be controlled by an actor other than the one who sent it.

However, now we have to decide how to classify browser-side sources like document.location. Who sent this data? By what definition is this even a "remote" flow source?

On one hand, one could argue that they were "sent" to the user by another web server from where the user was redirected (most CSRF attacks essentially start that way). From that viewpoint, they are indeed controlled by the sender of the data (the malicious web site), thus is not third-party controlled.

On the other hand, one could argue that any flow source of interest on the browser-side must come from a third party because the client trusts both himself and the server. Thus one would expect to use isThirdPartyControllable() in DomBasedXss and ClientSideUrlRedirect.

In any case, it was sufficiently non-obvious how to classify document.location, and that's why I opted for a definition that's less ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like you suggestion on moving it into RequestInputAccess, as that's essentially the same as saying it must be an "incoming request" (albeit restricted to HTTP requests).

@asger-semmle
Copy link
Contributor Author

I've moved it into RequestInputAccess and also added the Referer header as a source in ReflectedXss. The documentation has been rewritten.

Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

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

LGTM

@xiemaisi xiemaisi added the JS label Oct 8, 2018
@xiemaisi xiemaisi merged commit e354694 into github:master Oct 8, 2018
aibaars pushed a commit that referenced this pull request Oct 14, 2021
smowton added a commit to smowton/codeql that referenced this pull request Apr 16, 2022
…-test

Add test showing assign expressions
MathiasVP pushed a commit to MathiasVP/ql that referenced this pull request Nov 20, 2025
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.

2 participants