The Wayback Machine - http://web.archive.org/web/20220102121027/https://github.com/github/codeql/pull/7474
Skip to content
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

[draft] DB reads as taint sources #7474

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

@kaeluka
Copy link

@kaeluka kaeluka commented Dec 22, 2021

This adds DB reads as taint sources in AdditionalSources.qll as requested in github/codeql-javascript-team#348.

This is not yet complete, as it's not handling streaming database queries where the result is consumed by a pipe call (eg, knex, spanner, have such features).

This also partially fixes (not yet complete) github/codeql-javascript-team#355

@github-actions github-actions bot added the JS label Dec 22, 2021
@@ -57,6 +57,26 @@ module Knex {
)
}

override DataFlow::Node getAQueryArgument() { none() }
override DataFlow::Node getAResult() {
(
Copy link
Author

@kaeluka kaeluka Dec 22, 2021

Choose a reason for hiding this comment

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

the knex model is a bit unusual in that it classifies both the expression producing the promise, as well as the await expression as database accesses. getAResult, in this case, follows the implementation of the characteristic predicate. LMK what you think.

@@ -84,6 +84,7 @@ abstract class FileNameSource extends DataFlow::Node { }
abstract class DatabaseAccess extends DataFlow::Node {
/** Gets an argument to this database access that is interpreted as a query. */
abstract DataFlow::Node getAQueryArgument();
abstract DataFlow::Node getAResult();
Copy link
Contributor

@intrigus-lgtm intrigus-lgtm Dec 22, 2021

Choose a reason for hiding this comment

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

Missing Ql Doc.

(this = database().getMember("run").getACall() and result = this.getCallback(_).getParameter(1))
or
(this = transaction().getMember("run").getACall() and result = this.getCallback(_).getParameter(1))
or
(this = snapshot().getMember("run").getACall() and result = this.getCallback(_).getParameter(1))
Copy link
Contributor

@intrigus-lgtm intrigus-lgtm Dec 22, 2021

Choose a reason for hiding this comment

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

I think you should be able to simplify this using set-literals to

this = [database(), transaction(), snapshot()].getMember("run").getACall() and result = this.getCallback(_).getParameter(1))

@@ -52,3 +52,13 @@ class RemoteServerResponse extends HeuristicSource, RemoteFlowSource {

override string getSourceType() { result = "a response from a remote server" }
}

class DatabaseAccessResultRemoteFlowSource extends HeuristicSource, RemoteFlowSource {
Copy link
Contributor

@intrigus-lgtm intrigus-lgtm Dec 22, 2021

Choose a reason for hiding this comment

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

Missing Ql Doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants