@@ -8,127 +8,7 @@ import swift
88import codeql.swift.dataflow.DataFlow
99import codeql.swift.dataflow.TaintTracking
1010import codeql.swift.dataflow.FlowSources
11-
12- /**
13- * A `DataFlow::Node` that is a sink for a SQL string to be executed.
14- */
15- abstract class SqlSink extends DataFlow:: Node { }
16-
17- /**
18- * A sink for the sqlite3 C API.
19- */
20- class CApiSqlSink extends SqlSink {
21- CApiSqlSink ( ) {
22- // `sqlite3_exec` and variants of `sqlite3_prepare`.
23- exists ( CallExpr call |
24- call .getStaticTarget ( )
25- .( FreeFunctionDecl )
26- .hasName ( [
27- "sqlite3_exec(_:_:_:_:_:)" , "sqlite3_prepare(_:_:_:_:_:)" ,
28- "sqlite3_prepare_v2(_:_:_:_:_:)" , "sqlite3_prepare_v3(_:_:_:_:_:_:)" ,
29- "sqlite3_prepare16(_:_:_:_:_:)" , "sqlite3_prepare16_v2(_:_:_:_:_:)" ,
30- "sqlite3_prepare16_v3(_:_:_:_:_:_:)"
31- ] ) and
32- call .getArgument ( 1 ) .getExpr ( ) = this .asExpr ( )
33- )
34- }
35- }
36-
37- /**
38- * A sink for the SQLite.swift library.
39- */
40- class SQLiteSwiftSqlSink extends SqlSink {
41- SQLiteSwiftSqlSink ( ) {
42- // Variants of `Connection.execute`, `connection.prepare` and `connection.scalar`.
43- exists ( CallExpr call |
44- call .getStaticTarget ( )
45- .( MethodDecl )
46- .hasQualifiedName ( "Connection" ,
47- [ "execute(_:)" , "prepare(_:_:)" , "run(_:_:)" , "scalar(_:_:)" ] ) and
48- call .getArgument ( 0 ) .getExpr ( ) = this .asExpr ( )
49- )
50- or
51- // String argument to the `Statement` constructor.
52- exists ( CallExpr call |
53- call .getStaticTarget ( ) .( MethodDecl ) .hasQualifiedName ( "Statement" , "init(_:_:)" ) and
54- call .getArgument ( 1 ) .getExpr ( ) = this .asExpr ( )
55- )
56- }
57- }
58-
59- /** A sink for the GRDB library. */
60- class GrdbSqlSink extends SqlSink {
61- GrdbSqlSink ( ) {
62- exists ( CallExpr call , MethodDecl method |
63- call .getStaticTarget ( ) = method and
64- call .getArgument ( 0 ) .getExpr ( ) = this .asExpr ( )
65- |
66- method
67- .hasQualifiedName ( "Database" ,
68- [
69- "allStatements(sql:arguments:)" , "cachedStatement(sql:)" ,
70- "internalCachedStatement(sql:)" , "execute(sql:arguments:)" , "makeStatement(sql:)" ,
71- "makeStatement(sql:prepFlags:)"
72- ] )
73- or
74- method
75- .hasQualifiedName ( "SQLRequest" ,
76- [
77- "init(stringLiteral:)" , "init(unicodeScalarLiteral:)" ,
78- "init(extendedGraphemeClusterLiteral:)" , "init(stringInterpolation:)" ,
79- "init(sql:arguments:adapter:cached:)"
80- ] )
81- or
82- method
83- .hasQualifiedName ( "SQL" ,
84- [
85- "init(stringLiteral:)" , "init(unicodeScalarLiteral:)" ,
86- "init(extendedGraphemeClusterLiteral:)" , "init(stringInterpolation:)" ,
87- "init(sql:arguments:)" , "append(sql:arguments:)"
88- ] )
89- or
90- method
91- .hasQualifiedName ( "TableDefinition" , [ "column(sql:)" , "check(sql:)" , "constraint(sql:)" ] )
92- or
93- method .hasQualifiedName ( "TableAlteration" , "addColumn(sql:)" )
94- or
95- method
96- .hasQualifiedName ( "ColumnDefinition" ,
97- [ "check(sql:)" , "defaults(sql:)" , "generatedAs(sql:_:)" ] )
98- or
99- method
100- .hasQualifiedName ( "TableRecord" ,
101- [
102- "select(sql:arguments:)" , "select(sql:arguments:as:)" , "filter(sql:arguments:)" ,
103- "order(sql:arguments:)"
104- ] )
105- or
106- method .hasQualifiedName ( "StatementCache" , "statement(_:)" )
107- )
108- or
109- exists ( CallExpr call , MethodDecl method |
110- call .getStaticTarget ( ) = method and
111- call .getArgument ( 1 ) .getExpr ( ) = this .asExpr ( )
112- |
113- method
114- .hasQualifiedName ( [ "Row" , "DatabaseValueConvertible" ] ,
115- [
116- "fetchCursor(_:sql:arguments:adapter:)" , "fetchAll(_:sql:arguments:adapter:)" ,
117- "fetchSet(_:sql:arguments:adapter:)" , "fetchOne(_:sql:arguments:adapter:)"
118- ] )
119- or
120- method .hasQualifiedName ( "SQLStatementCursor" , "init(database:sql:arguments:prepFlags:)" )
121- )
122- or
123- exists ( CallExpr call , MethodDecl method |
124- call .getStaticTarget ( ) = method and
125- call .getArgument ( 3 ) .getExpr ( ) = this .asExpr ( )
126- |
127- method
128- .hasQualifiedName ( "CommonTableExpression" , "init(recursive:named:columns:sql:arguments:)" )
129- )
130- }
131- }
11+ import codeql.swift.security.SqlInjectionExtensions
13212
13313/**
13414 * A taint configuration for tainted data that reaches a SQL sink.
0 commit comments