Skip to content

JS: js/reflected-xss through file names#142

Closed
ghost wants to merge 6 commits intomasterfrom
unknown repository
Closed

JS: js/reflected-xss through file names#142
ghost wants to merge 6 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Sep 3, 2018

This PR makes js/reflected-xss treat file names as sources.

Other injection queries, such as js/sql-injection, can perhaps also use this new source, but I would like to introduce this source slowly to prevent too many FPs at once if it turns out that file names in practice are benign.

The PR is inspired by this vulnerability fix: nunnly/m-server@b8613fd, where a file name ultimately is concatenated with some HTML string fragments.

Performance and results are unchanged, except for a result that I suspect is a FP due to a non-HTML response content-type that we fail to identify.

I have started on the 1.19 changes notes. I think we should aim for a less verbose library listing this time. I think a category and an example library is fine WDYT?

@ghost ghost added the JS label Sep 3, 2018
@ghost ghost self-requested a review as a code owner September 3, 2018 13:58
Copy link
Copy Markdown

@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, only one question and a minor suggestion. OOI, why do you think the content-type in the newly identified result is non-HTML?

}

/**
* A data flow node that contains one or more file names from the local file system.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why "one or more"?

}
}

/** A source of file name input, considered as a flow source for reflected XSS. */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The phrase "source of file name input" sounds quite awkward. Maybe just "a file name"?

@ghost
Copy link
Copy Markdown
Author

ghost commented Sep 4, 2018

Comments addressed.

OOI, why do you think the content-type in the newly identified result is non-HTML?

Several reasons:

  • the file name is the only element in the response
  • it is on a /debug/ route
  • the endpoint is used by other code in the same project, where it is embedded as an attribute value

@xiemaisi
Copy link
Copy Markdown

xiemaisi commented Sep 4, 2018

Query LGTM, but I'm having second thoughts about adding this as a source for reflected XSS. The alert message is phrased in terms of user-provided values, and I don't really think local file system paths fit into that category. Is this perhaps a separate query? (Ping @asger-semmle for input.)

@asger-semmle
Copy link
Copy Markdown
Contributor

I don't understand the vulnerability you want to flag here?

As far as I can tell, the commit doesn't actually fix anything. It's a static file server, so attackers have no control over file names.

If they could upload files and thereby control file names, I'd categorize it as stored XSS.

@ghost
Copy link
Copy Markdown
Author

ghost commented Sep 4, 2018

I don't understand the vulnerability you want to flag here?

It is a vulnerability, no doubt about that (hackerone agrees).
It is dangerous to rely on the format of strings that the application does not control at all.

If they could upload files and thereby control file names,

They do not have to choose the file names through the application with the XSS vulnerability. Imagine an escalation through a compromised FTP server with a directory that happens to be served by m-server...

I'd categorize it as stored XSS.

Yes, the source should perhaps be moved to XSS.ql, I had a wrong definition in mind. Reflected XSS is not stored, by definition:

OWASP:

Reflected XSS is also sometimes referred to as Non-Persistent or Type-II XSS

@xiemaisi
Copy link
Copy Markdown

xiemaisi commented Sep 4, 2018

I like Asger's suggestion of treating this as a stored XSS. We don't have a query for that yet (merging into XSS.ql doesn't seem right; that query is for DOM-based XSS), but adding one would increase our claimed security coverage, which is a good thing.

@ghost
Copy link
Copy Markdown
Author

ghost commented Sep 4, 2018

OK. Closing for now then.

@ghost ghost closed this Sep 4, 2018
Copy link
Copy Markdown
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.

Thanks for the clarification.

+1 for moving into a new query. Either one for stored xss, and/or one whose alert message clarifies that it can be used to escalate other vulnerabilities (and thus may not be exploitable as reported).

I still think this is sort of a downwards escalation, as getting write access to the server would almost certainly enable you to XSS its visitors anyway.

NodeJSFileNameSource() {
exists (string name |
name = "readdir" or
name = "realpath" |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would the FP you found go away if realpath became a taint step instead of a source?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I believe so, but I still think it should remain a source.
If we later find that readdir or realpath cause many FPs as sources, we can downgrade them to taint steps.

@ghost
Copy link
Copy Markdown
Author

ghost commented Sep 4, 2018

I still think this is sort of a downwards escalation, as getting write access to the server would almost certainly enable you to XSS its visitors anyway.

You escalate from an access to some file server, you do not have access to the application server that displays the XSSed listing of files.

@ghost ghost mentioned this pull request Sep 14, 2018
aibaars added a commit that referenced this pull request Oct 14, 2021
Remove as many references to TreeSitter::Generated
smowton pushed a commit to smowton/codeql that referenced this pull request Dec 6, 2021
Kotlin: Expressions: Improve test
MathiasVP pushed a commit to MathiasVP/ql that referenced this pull request Aug 10, 2025
…ldmodes

PS: support buildmode none in extractor
This pull request was closed.
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