mirror of
https://github.com/github/codeql.git
synced 2026-01-29 14:23:03 +01:00
Merge branch 'standard-lib-pt-9' into stdlib-339-340-342-346-347
This commit is contained in:
@@ -6,6 +6,79 @@ import go
|
||||
|
||||
/** Provides classes for working with SQL-related APIs. */
|
||||
module SQL {
|
||||
private class SqlFunctionModels extends TaintTracking::FunctionModel {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
SqlFunctionModels() {
|
||||
// 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 SqlMethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
SqlMethodModels() {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
private class SqlDriverMethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
SqlDriverMethodModels() {
|
||||
// signature: func (NotNull).ConvertValue(v interface{}) (Value, error)
|
||||
this.hasQualifiedName("database/sql/driver", "NotNull", "ConvertValue") and
|
||||
(inp.isParameter(0) and outp.isResult(0))
|
||||
or
|
||||
// signature: func (Null).ConvertValue(v interface{}) (Value, error)
|
||||
this.hasQualifiedName("database/sql/driver", "Null", "ConvertValue") and
|
||||
(inp.isParameter(0) and outp.isResult(0))
|
||||
or
|
||||
// signature: func (ValueConverter).ConvertValue(v interface{}) (Value, error)
|
||||
this.implements("database/sql/driver", "ValueConverter", "ConvertValue") and
|
||||
(inp.isParameter(0) and outp.isResult(0))
|
||||
or
|
||||
// signature: func (Conn).Prepare(query string) (Stmt, error)
|
||||
this.implements("database/sql/driver", "Conn", "Prepare") and
|
||||
(inp.isParameter(0) and outp.isResult(0))
|
||||
or
|
||||
// signature: func (ConnPrepareContext).PrepareContext(ctx context.Context, query string) (Stmt, error)
|
||||
this.implements("database/sql/driver", "ConnPrepareContext", "PrepareContext") and
|
||||
(inp.isParameter(1) and outp.isResult(0))
|
||||
or
|
||||
// signature: func (Valuer).Value() (Value, error)
|
||||
this.implements("database/sql/driver", "Valuer", "Value") and
|
||||
(inp.isReceiver() and outp.isResult(0))
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
@@ -34,7 +107,8 @@ module SQL {
|
||||
exists(Method meth, string base, string m, int n |
|
||||
(
|
||||
meth.hasQualifiedName("database/sql", "DB", m) or
|
||||
meth.hasQualifiedName("database/sql", "Tx", m)
|
||||
meth.hasQualifiedName("database/sql", "Tx", m) or
|
||||
meth.hasQualifiedName("database/sql", "Conn", m)
|
||||
) and
|
||||
this = meth.getACall().getArgument(n)
|
||||
|
|
||||
@@ -48,6 +122,29 @@ module SQL {
|
||||
}
|
||||
}
|
||||
|
||||
/** A query string used in an API function of the standard `database/sql/driver` package. */
|
||||
private class DriverQueryString extends Range {
|
||||
DriverQueryString() {
|
||||
exists(Method meth, int n |
|
||||
(
|
||||
meth.hasQualifiedName("database/sql/driver", "Execer", "Exec") and n = 0
|
||||
or
|
||||
meth.hasQualifiedName("database/sql/driver", "ExecerContext", "ExecContext") and n = 1
|
||||
or
|
||||
meth.hasQualifiedName("database/sql/driver", "Conn", "Prepare") and n = 0
|
||||
or
|
||||
meth.hasQualifiedName("database/sql/driver", "ConnPrepareContext", "PrepareContext") and
|
||||
n = 1
|
||||
or
|
||||
meth.hasQualifiedName("database/sql/driver", "Queryer", "Query") and n = 0
|
||||
or
|
||||
meth.hasQualifiedName("database/sql/driver", "QueryerContext", "QueryContext") and n = 1
|
||||
) and
|
||||
this = meth.getACall().getArgument(n)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An argument to an API of the squirrel library that is directly interpreted as SQL without
|
||||
* taking syntactic structure into account.
|
||||
|
||||
@@ -40,6 +40,8 @@ import semmle.go.frameworks.stdlib.NetTextproto
|
||||
import semmle.go.frameworks.stdlib.Log
|
||||
import semmle.go.frameworks.stdlib.Io
|
||||
import semmle.go.frameworks.stdlib.IoIoutil
|
||||
import semmle.go.frameworks.stdlib.Errors
|
||||
import semmle.go.frameworks.stdlib.Expvar
|
||||
import semmle.go.frameworks.stdlib.Path
|
||||
import semmle.go.frameworks.stdlib.PathFilepath
|
||||
import semmle.go.frameworks.stdlib.Reflect
|
||||
|
||||
31
ql/src/semmle/go/frameworks/stdlib/Errors.qll
Normal file
31
ql/src/semmle/go/frameworks/stdlib/Errors.qll
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Provides classes modeling security-relevant aspects of the `errors` package.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
/** Provides models of commonly used functions in the `errors` package. */
|
||||
module Errors {
|
||||
private class FunctionModels extends TaintTracking::FunctionModel {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
FunctionModels() {
|
||||
// signature: func As(err error, target interface{}) bool
|
||||
hasQualifiedName("errors", "As") and
|
||||
(inp.isParameter(0) and outp.isParameter(1))
|
||||
or
|
||||
// signature: func New(text string) error
|
||||
hasQualifiedName("errors", "New") and
|
||||
(inp.isParameter(0) and outp.isResult())
|
||||
or
|
||||
// signature: func Unwrap(err error) error
|
||||
hasQualifiedName("errors", "Unwrap") and
|
||||
(inp.isParameter(0) and outp.isResult())
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
}
|
||||
51
ql/src/semmle/go/frameworks/stdlib/Expvar.qll
Normal file
51
ql/src/semmle/go/frameworks/stdlib/Expvar.qll
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Provides classes modeling security-relevant aspects of the `expvar` package.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
/** Provides models of commonly used functions in the `expvar` package. */
|
||||
module Expvar {
|
||||
private class MethodModels extends TaintTracking::FunctionModel, Method {
|
||||
FunctionInput inp;
|
||||
FunctionOutput outp;
|
||||
|
||||
MethodModels() {
|
||||
// signature: func (Func).Value() interface{}
|
||||
this.hasQualifiedName("expvar", "Func", "Value") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
or
|
||||
// signature: func (*Map).Get(key string) Var
|
||||
this.hasQualifiedName("expvar", "Map", "Get") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
or
|
||||
// signature: func (*Map).Set(key string, av Var)
|
||||
this.hasQualifiedName("expvar", "Map", "Set") and
|
||||
(inp.isParameter(_) and outp.isReceiver())
|
||||
or
|
||||
// signature: func (*Map).String() string
|
||||
this.hasQualifiedName("expvar", "Map", "String") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
or
|
||||
// signature: func (*String).Set(value string)
|
||||
this.hasQualifiedName("expvar", "String", "Set") and
|
||||
(inp.isParameter(0) and outp.isReceiver())
|
||||
or
|
||||
// signature: func (*String).String() string
|
||||
this.hasQualifiedName("expvar", "String", "String") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
or
|
||||
// signature: func (*String).Value() string
|
||||
this.hasQualifiedName("expvar", "String", "Value") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
or
|
||||
// signature: func (Var).String() string
|
||||
this.implements("expvar", "Var", "String") and
|
||||
(inp.isReceiver() and outp.isResult())
|
||||
}
|
||||
|
||||
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
|
||||
input = inp and output = outp
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import "database/sql"
|
||||
|
||||
func TaintStepTest_DatabaseSqlNamed_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString656 := sourceCQL.(string)
|
||||
intoNamedArg414 := sql.Named(fromString656, nil)
|
||||
return intoNamedArg414
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlNamed_B0I1O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface518 := sourceCQL.(interface{})
|
||||
intoNamedArg650 := sql.Named("", fromInterface518)
|
||||
return intoNamedArg650
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlNullStringScan_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface784 := sourceCQL.(interface{})
|
||||
var intoNullString957 sql.NullString
|
||||
intoNullString957.Scan(fromInterface784)
|
||||
return intoNullString957
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlRowScan_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromRow520 := sourceCQL.(sql.Row)
|
||||
var intoInterface443 interface{}
|
||||
fromRow520.Scan(intoInterface443)
|
||||
return intoInterface443
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlRowsScan_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromRows127 := sourceCQL.(sql.Rows)
|
||||
var intoInterface483 interface{}
|
||||
fromRows127.Scan(intoInterface483)
|
||||
return intoInterface483
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlScannerScan_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface989 := sourceCQL.(interface{})
|
||||
var intoScanner982 sql.Scanner
|
||||
intoScanner982.Scan(fromInterface989)
|
||||
return intoScanner982
|
||||
}
|
||||
|
||||
func RunAllTaints_DatabaseSql() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_DatabaseSqlNamed_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_DatabaseSqlNamed_B0I1O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_DatabaseSqlNullStringScan_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
{
|
||||
source := newSource(3)
|
||||
out := TaintStepTest_DatabaseSqlRowScan_B0I0O0(source)
|
||||
sink(3, out)
|
||||
}
|
||||
{
|
||||
source := newSource(4)
|
||||
out := TaintStepTest_DatabaseSqlRowsScan_B0I0O0(source)
|
||||
sink(4, out)
|
||||
}
|
||||
{
|
||||
source := newSource(5)
|
||||
out := TaintStepTest_DatabaseSqlScannerScan_B0I0O0(source)
|
||||
sink(5, out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import "database/sql/driver"
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverNotNullConvertValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface656 := sourceCQL.(interface{})
|
||||
var mediumObjCQL driver.NotNull
|
||||
intoValue414, _ := mediumObjCQL.ConvertValue(fromInterface656)
|
||||
return intoValue414
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverNullConvertValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface518 := sourceCQL.(interface{})
|
||||
var mediumObjCQL driver.Null
|
||||
intoValue650, _ := mediumObjCQL.ConvertValue(fromInterface518)
|
||||
return intoValue650
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverValueConverterConvertValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromInterface784 := sourceCQL.(interface{})
|
||||
var mediumObjCQL driver.ValueConverter
|
||||
intoValue957, _ := mediumObjCQL.ConvertValue(fromInterface784)
|
||||
return intoValue957
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverConnPrepare_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString520 := sourceCQL.(string)
|
||||
var mediumObjCQL driver.Conn
|
||||
intoStmt443, _ := mediumObjCQL.Prepare(fromString520)
|
||||
return intoStmt443
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverConnPrepareContextPrepareContext_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString127 := sourceCQL.(string)
|
||||
var mediumObjCQL driver.ConnPrepareContext
|
||||
intoStmt483, _ := mediumObjCQL.PrepareContext(nil, fromString127)
|
||||
return intoStmt483
|
||||
}
|
||||
|
||||
func TaintStepTest_DatabaseSqlDriverValuerValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromValuer989 := sourceCQL.(driver.Valuer)
|
||||
intoValue982, _ := fromValuer989.Value()
|
||||
return intoValue982
|
||||
}
|
||||
|
||||
func RunAllTaints_DatabaseSqlDriver() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_DatabaseSqlDriverNotNullConvertValue_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_DatabaseSqlDriverNullConvertValue_B0I0O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_DatabaseSqlDriverValueConverterConvertValue_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
{
|
||||
source := newSource(3)
|
||||
out := TaintStepTest_DatabaseSqlDriverConnPrepare_B0I0O0(source)
|
||||
sink(3, out)
|
||||
}
|
||||
{
|
||||
source := newSource(4)
|
||||
out := TaintStepTest_DatabaseSqlDriverConnPrepareContextPrepareContext_B0I0O0(source)
|
||||
sink(4, out)
|
||||
}
|
||||
{
|
||||
source := newSource(5)
|
||||
out := TaintStepTest_DatabaseSqlDriverValuerValue_B0I0O0(source)
|
||||
sink(5, out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
func TaintStepTest_ErrorsAs_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromError656 := sourceCQL.(error)
|
||||
var intoInterface414 interface{}
|
||||
errors.As(fromError656, intoInterface414)
|
||||
return intoInterface414
|
||||
}
|
||||
|
||||
func TaintStepTest_ErrorsNew_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString518 := sourceCQL.(string)
|
||||
intoError650 := errors.New(fromString518)
|
||||
return intoError650
|
||||
}
|
||||
|
||||
func TaintStepTest_ErrorsUnwrap_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromError784 := sourceCQL.(error)
|
||||
intoError957 := errors.Unwrap(fromError784)
|
||||
return intoError957
|
||||
}
|
||||
|
||||
func RunAllTaints_Errors() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_ErrorsAs_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_ErrorsNew_B0I0O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_ErrorsUnwrap_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import "expvar"
|
||||
|
||||
func TaintStepTest_ExpvarFuncValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromFunc656 := sourceCQL.(expvar.Func)
|
||||
intoInterface414 := fromFunc656.Value()
|
||||
return intoInterface414
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarMapGet_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromMap518 := sourceCQL.(expvar.Map)
|
||||
intoVar650 := fromMap518.Get("")
|
||||
return intoVar650
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarMapSet_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString784 := sourceCQL.(string)
|
||||
var intoMap957 expvar.Map
|
||||
intoMap957.Set(fromString784, nil)
|
||||
return intoMap957
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarMapSet_B0I1O0(sourceCQL interface{}) interface{} {
|
||||
fromVar520 := sourceCQL.(expvar.Var)
|
||||
var intoMap443 expvar.Map
|
||||
intoMap443.Set("", fromVar520)
|
||||
return intoMap443
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarMapString_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromMap127 := sourceCQL.(expvar.Map)
|
||||
intoString483 := fromMap127.String()
|
||||
return intoString483
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarStringSet_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString989 := sourceCQL.(string)
|
||||
var intoString982 expvar.String
|
||||
intoString982.Set(fromString989)
|
||||
return intoString982
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarStringString_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString417 := sourceCQL.(expvar.String)
|
||||
intoString584 := fromString417.String()
|
||||
return intoString584
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarStringValue_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromString991 := sourceCQL.(expvar.String)
|
||||
intoString881 := fromString991.Value()
|
||||
return intoString881
|
||||
}
|
||||
|
||||
func TaintStepTest_ExpvarVarString_B0I0O0(sourceCQL interface{}) interface{} {
|
||||
fromVar186 := sourceCQL.(expvar.Var)
|
||||
intoString284 := fromVar186.String()
|
||||
return intoString284
|
||||
}
|
||||
|
||||
func RunAllTaints_Expvar() {
|
||||
{
|
||||
source := newSource(0)
|
||||
out := TaintStepTest_ExpvarFuncValue_B0I0O0(source)
|
||||
sink(0, out)
|
||||
}
|
||||
{
|
||||
source := newSource(1)
|
||||
out := TaintStepTest_ExpvarMapGet_B0I0O0(source)
|
||||
sink(1, out)
|
||||
}
|
||||
{
|
||||
source := newSource(2)
|
||||
out := TaintStepTest_ExpvarMapSet_B0I0O0(source)
|
||||
sink(2, out)
|
||||
}
|
||||
{
|
||||
source := newSource(3)
|
||||
out := TaintStepTest_ExpvarMapSet_B0I1O0(source)
|
||||
sink(3, out)
|
||||
}
|
||||
{
|
||||
source := newSource(4)
|
||||
out := TaintStepTest_ExpvarMapString_B0I0O0(source)
|
||||
sink(4, out)
|
||||
}
|
||||
{
|
||||
source := newSource(5)
|
||||
out := TaintStepTest_ExpvarStringSet_B0I0O0(source)
|
||||
sink(5, out)
|
||||
}
|
||||
{
|
||||
source := newSource(6)
|
||||
out := TaintStepTest_ExpvarStringString_B0I0O0(source)
|
||||
sink(6, out)
|
||||
}
|
||||
{
|
||||
source := newSource(7)
|
||||
out := TaintStepTest_ExpvarStringValue_B0I0O0(source)
|
||||
sink(7, out)
|
||||
}
|
||||
{
|
||||
source := newSource(8)
|
||||
out := TaintStepTest_ExpvarVarString_B0I0O0(source)
|
||||
sink(8, out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user