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 11import swift
2+ private import codeql.swift.dataflow.DataFlow
23private import codeql.swift.dataflow.ExternalFlow
4+ private import codeql.swift.dataflow.FlowSteps
35
46private class StringSource extends SourceModelCsv {
57 override predicate row ( string row ) {
@@ -16,3 +18,15 @@ private class StringSource extends SourceModelCsv {
1618 ]
1719 }
1820}
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() {
8282 sink ( arg: String ( repeating: tainted, count: 2 ) ) // $ MISSING: tainted=74
8383
8484 sink ( arg: clean. description)
85- sink ( arg: tainted. description) // $ MISSING: tainted=74
85+ sink ( arg: tainted. description) // $ tainted=74
8686
8787 sink ( arg: clean. debugDescription)
88- sink ( arg: tainted. debugDescription) // $ MISSING: tainted=74
88+ sink ( arg: tainted. debugDescription) // $ tainted=74
8989}
9090
9191class Data
@@ -111,3 +111,13 @@ func taintThroughData() {
111111 sink ( arg: stringClean!)
112112 sink ( arg: stringTainted!) // $ MISSING: tainted=100
113113}
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