Skip to content

Commit

Permalink
Add taint-tracking to database/sql package in the SQL module
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Sep 20, 2020
1 parent 55a8e24 commit 6f0bfbf
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ql/src/semmle/go/frameworks/SQL.qll
Expand Up @@ -6,6 +6,48 @@ import go

/** Provides classes for working with SQL-related APIs. */
module SQL {
private class FunctionModels extends TaintTracking::FunctionModel {
FunctionInput inp;
FunctionOutput outp;

FunctionModels() {
// signature: func Named(name string, value interface{}) NamedArg
hasQualifiedName("database/sql", "Named") and
(inp.isParameter(_) and outp.isResult())
}

override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input = inp and output = outp
}
}

private class MethodModels extends TaintTracking::FunctionModel, Method {
FunctionInput inp;
FunctionOutput outp;

MethodModels() {
// signature: func (*NullString).Scan(value interface{}) error
this.hasQualifiedName("database/sql", "NullString", "Scan") and
(inp.isParameter(0) and outp.isReceiver())
or
// signature: func (*Row).Scan(dest ...interface{}) error
this.hasQualifiedName("database/sql", "Row", "Scan") and
(inp.isReceiver() and outp.isParameter(_))
or
// signature: func (*Rows).Scan(dest ...interface{}) error
this.hasQualifiedName("database/sql", "Rows", "Scan") and
(inp.isReceiver() and outp.isParameter(_))
or
// signature: func (Scanner).Scan(src interface{}) error
this.implements("database/sql", "Scanner", "Scan") and
(inp.isParameter(0) and outp.isReceiver())
}

override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input = inp and output = outp
}
}

/**
* A data-flow node whose string value is interpreted as (part of) a SQL query.
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f0bfbf

Please sign in to comment.