Skip to content

JS: change alert messages of path queries to use the same template #10286

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

Merged
merged 6 commits into from
Sep 20, 2022

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Sep 2, 2022

I just did this for Python: #10252, now I'm doing the same thing for JavaScript.

I'm rewriting alert messages for the taint tracking queries:

  • I tried to fit the message to the template: This path depends on a user-provided value.
  • If that didn't work I tried User-provided value flows to this location and is used in a path.

I also generally tried to use "this location" instead of "here".
I tried to formulate messages to use "depends on" and use the term "a user-provided value".

The previous change-note for changing the alert messages still cover this PR.

@erik-krogh erik-krogh added the no-change-note-required This PR does not need a change note label Sep 5, 2022
@erik-krogh erik-krogh marked this pull request as ready for review September 5, 2022 12:22
@erik-krogh erik-krogh requested a review from a team as a code owner September 5, 2022 12:22
@erik-krogh erik-krogh added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Sep 5, 2022
@martin389
Copy link

Hello from this week's docs first responder 👋 Thanks for creating this PR! I've added it to our review board for another writer to look at. They'll be able to advise on any additional considerations for this change.

felicitymay
felicitymay previously approved these changes Sep 12, 2022
Copy link
Contributor

@felicitymay felicitymay left a comment

Choose a reason for hiding this comment

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

@erik-krogh - many thanks for continuing to improve the consistency and clarity of our alert comments ✨

As you work on this, it would be great if you could update the Style guide with the patterns you've implemented for common situations.

This generally looks good to me, as far as I can interpret the statements. I've added a few questions and comments for your consideration.

@@ -28,5 +28,5 @@ where
else highlight = sink.getNode()
) and
sourceNode = source.getNode()
select highlight, source, sink, "$@ flows to here and is used in a command.", source.getNode(),
sourceNode.getSourceType()
select highlight, source, sink, "This command line depends on $@.", source.getNode(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice that for this query you include "This" but that this is omitted in TemplateObjectInjection.ql. Do you have a rule of thumb for deciding when to include "This" and when to omit it.

I'm wondering if we should update https://github.com/github/codeql/blob/main/docs/query-metadata-style-guide.md#alert-messages, based on your work on select statements.

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 notice that for this query you include "This" but that this is omitted in TemplateObjectInjection.ql. Do you have a rule of thumb for deciding when to include "This" and when to omit it.

I don't have a rule of thumb, I think it was a coincidence.
I think I prefer the more concise version without "This", so I'll remove the "This" from CommandInjection.ql.

I'm wondering if we should update https://github.com/github/codeql/blob/main/docs/query-metadata-style-guide.md#alert-messages, based on your work on select statements.

We should! I'll get on that when I rewrite the alert-messages for the next language (after merging this PR).

Comment on lines 22 to 24
select sinkNode.getAlertLocation(), source, sink, "$@ which depends on $@ is later used in $@.",
sinkNode.getAlertLocation(), sinkNode.getSinkType(), source.getNode(), "library input",
sinkNode.getCommandExecution(), "shell command"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should contain an article, similar to other select statements? This suggestion is something of a guess.

Suggested change
select sinkNode.getAlertLocation(), source, sink, "$@ which depends on $@ is later used in $@.",
sinkNode.getAlertLocation(), sinkNode.getSinkType(), source.getNode(), "library input",
sinkNode.getCommandExecution(), "shell command"
select sinkNode.getAlertLocation(), source, sink, "$@ which depends on $@ is later used in $@.",
sinkNode.getAlertLocation(), sinkNode.getSinkType(), source.getNode(), "library input",
sinkNode.getCommandExecution(), "a shell command"

@@ -18,6 +18,6 @@ import semmle.javascript.security.dataflow.UnsafeHtmlConstructionQuery

from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, Sink sinkNode
where cfg.hasFlowPath(source, sink) and sink.getNode() = sinkNode
select sinkNode, source, sink, "$@ based on $@ might later cause $@.", sinkNode,
select sinkNode, source, sink, "$@ which depends on $@ might later cause $@.", sinkNode,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually cause cross-site scripting, or might it be vulnerable to cross-site scripting?

I see that UnsafeDynamicMethodAccess.ql below uses: "may lead to remote code execution".

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 query detects something that appears unsafe, but that's not a full exploitable vulnerability.
The full vulnerability requires that the library (flagged by the query) is used with unsafe inputs in some other project.

So that's why there is a "might" in the alert message.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest replacing "cause" since the code doesn't cause cross-site scripting, it seems more as if it "allows" a hacker to perform cross-site scripting.

Suggested change
select sinkNode, source, sink, "$@ which depends on $@ might later cause $@.", sinkNode,
select sinkNode, source, sink, "$@ which depends on $@ might later allow $@.", sinkNode,

@@ -18,4 +18,4 @@ from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink, source, sink,
"Invocation of method derived from $@ may lead to remote code execution.", source.getNode(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be more like:

Suggested change
"Invocation of method derived from $@ may lead to remote code execution.", source.getNode(),
"This method is invoked using $@, which may allow remote code execution.", source.getNode(),

@@ -18,5 +18,5 @@ import DataFlow::PathGraph

from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "A $@ is used as" + sink.getNode().(Sink).getMessage(),
select sink.getNode(), source, sink, sink.getNode().(Sink).getMessage() + " depends on $@.",
source.getNode(), "user-provided value"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
source.getNode(), "user-provided value"
source.getNode(), "a user-provided value"

Comment on lines 22 to 23
"Iterating over user-controlled object with a potentially unbounded .length property from $@.",
source, "here"
source, "a user-provided value"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe more like this (it won't let me add a suggestion).

"Iteration over a user-controlled object with a potentially unbounded .length property from $@.",
  source, "a user-provided value"

@calumgrant calumgrant requested a review from asgerf September 12, 2022 12:45
Copy link
Contributor

@felicitymay felicitymay 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 updates. Happy for this to be merged once it's okayed by the JavaScript team.

@erik-krogh erik-krogh removed the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants