File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
lib/codeql/swift/frameworks/StandardLibrary
test/library-tests/dataflow/taint Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
1
import swift
2
+ private import codeql.swift.dataflow.DataFlow
2
3
private import codeql.swift.dataflow.ExternalFlow
4
+ private import codeql.swift.dataflow.FlowSteps
3
5
4
6
private class StringSource extends SourceModelCsv {
5
7
override predicate row ( string row ) {
@@ -16,3 +18,15 @@ private class StringSource extends SourceModelCsv {
16
18
]
17
19
}
18
20
}
21
+
22
+ /**
23
+ * A content implying that, if a `String` is tainted, then all its fields are tainted.
24
+ */
25
+ private class StringFieldsInheritTaint extends TaintInheritingContent ,
26
+ DataFlow:: Content:: FieldContent {
27
+ StringFieldsInheritTaint ( ) {
28
+ this .getField ( ) .getEnclosingDecl ( ) .( ClassOrStructDecl ) .getFullName ( ) = "String" or
29
+ this .getField ( ) .getEnclosingDecl ( ) .( ExtensionDecl ) .getExtendedTypeDecl ( ) .getFullName ( ) =
30
+ "String"
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -82,10 +82,10 @@ func taintThroughStringOperations() {
82
82
sink ( arg: String ( repeating: tainted, count: 2 ) ) // $ MISSING: tainted=74
83
83
84
84
sink ( arg: clean. description)
85
- sink ( arg: tainted. description) // $ MISSING: tainted=74
85
+ sink ( arg: tainted. description) // $ tainted=74
86
86
87
87
sink ( arg: clean. debugDescription)
88
- sink ( arg: tainted. debugDescription) // $ MISSING: tainted=74
88
+ sink ( arg: tainted. debugDescription) // $ tainted=74
89
89
}
90
90
91
91
class Data
@@ -111,3 +111,13 @@ func taintThroughData() {
111
111
sink ( arg: stringClean!)
112
112
sink ( arg: stringTainted!) // $ MISSING: tainted=100
113
113
}
114
+
115
+ func sink( arg: String . UTF8View ) { }
116
+
117
+ func taintThroughStringFields( ) {
118
+ let clean = " "
119
+ let tainted = source2 ( ) . utf8
120
+
121
+ sink ( arg: clean)
122
+ sink ( arg: tainted) // $ tainted=95
123
+ }
You can’t perform that action at this time.
0 commit comments