Skip to content

Commit 30468dd

Browse files
committed
Swift: Implement field content as well.
1 parent ffbd201 commit 30468dd

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/WebView.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,16 @@ private class WKUserScriptSummaries extends SummaryModelCsv {
144144
]
145145
}
146146
}
147+
148+
/**
149+
* A content implying that, if a `WKUserScript` is tainted, its `source` field is tainted.
150+
*/
151+
private class WKUserScriptInheritsTaint extends TaintInheritingContent,
152+
DataFlow::Content::FieldContent {
153+
WKUserScriptInheritsTaint() {
154+
exists(FieldDecl f | this.getField() = f |
155+
f.getEnclosingDecl().(ClassOrStructDecl).getName() = "WKUserScript" and
156+
f.getName() = "source"
157+
)
158+
}
159+
}

swift/ql/test/library-tests/dataflow/taint/LocalTaint.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,6 @@
166166
| url.swift:101:15:101:57 | ...! | url.swift:101:15:101:59 | .user |
167167
| url.swift:102:15:102:57 | ...! | url.swift:102:15:102:59 | .password |
168168
| webview.swift:77:11:77:18 | call to source() | webview.swift:77:10:77:41 | .body |
169+
| webview.swift:130:10:130:10 | a | webview.swift:130:10:130:12 | .source |
170+
| webview.swift:134:10:134:10 | b | webview.swift:134:10:134:12 | .source |
171+
| webview.swift:139:10:139:10 | c | webview.swift:139:10:139:12 | .source |

swift/ql/test/library-tests/dataflow/taint/Taint.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,11 @@ edges
533533
| webview.swift:122:17:122:17 | s : | webview.swift:55:5:55:48 | [summary param] 0 in setValue(_:forProperty:) : |
534534
| webview.swift:122:17:122:17 | s : | webview.swift:122:5:122:5 | [post] v3 : |
535535
| webview.swift:132:13:132:102 | call to init(source:injectionTime:forMainFrameOnly:) : | webview.swift:133:10:133:10 | b |
536+
| webview.swift:132:13:132:102 | call to init(source:injectionTime:forMainFrameOnly:) : | webview.swift:134:10:134:12 | .source |
536537
| webview.swift:132:34:132:41 | call to source() : | webview.swift:65:5:65:93 | [summary param] 0 in init(source:injectionTime:forMainFrameOnly:) : |
537538
| webview.swift:132:34:132:41 | call to source() : | webview.swift:132:13:132:102 | call to init(source:injectionTime:forMainFrameOnly:) : |
538539
| webview.swift:137:13:137:113 | call to init(source:injectionTime:forMainFrameOnly:in:) : | webview.swift:138:10:138:10 | c |
540+
| webview.swift:137:13:137:113 | call to init(source:injectionTime:forMainFrameOnly:in:) : | webview.swift:139:10:139:12 | .source |
539541
| webview.swift:137:34:137:41 | call to source() : | webview.swift:66:5:66:126 | [summary param] 0 in init(source:injectionTime:forMainFrameOnly:in:) : |
540542
| webview.swift:137:34:137:41 | call to source() : | webview.swift:137:13:137:113 | call to init(source:injectionTime:forMainFrameOnly:in:) : |
541543
nodes
@@ -1131,9 +1133,11 @@ nodes
11311133
| webview.swift:132:13:132:102 | call to init(source:injectionTime:forMainFrameOnly:) : | semmle.label | call to init(source:injectionTime:forMainFrameOnly:) : |
11321134
| webview.swift:132:34:132:41 | call to source() : | semmle.label | call to source() : |
11331135
| webview.swift:133:10:133:10 | b | semmle.label | b |
1136+
| webview.swift:134:10:134:12 | .source | semmle.label | .source |
11341137
| webview.swift:137:13:137:113 | call to init(source:injectionTime:forMainFrameOnly:in:) : | semmle.label | call to init(source:injectionTime:forMainFrameOnly:in:) : |
11351138
| webview.swift:137:34:137:41 | call to source() : | semmle.label | call to source() : |
11361139
| webview.swift:138:10:138:10 | c | semmle.label | c |
1140+
| webview.swift:139:10:139:12 | .source | semmle.label | .source |
11371141
subpaths
11381142
| data.swift:89:41:89:48 | call to source() : | data.swift:25:2:25:66 | [summary param] 0 in init(base64Encoded:options:) : | file://:0:0:0:0 | [summary] to write: return (return) in init(base64Encoded:options:) : | data.swift:89:21:89:71 | call to init(base64Encoded:options:) : |
11391143
| data.swift:93:34:93:41 | call to source() : | data.swift:26:2:26:61 | [summary param] 0 in init(buffer:) : | file://:0:0:0:0 | [summary] to write: return (return) in init(buffer:) : | data.swift:93:21:93:73 | call to init(buffer:) : |
@@ -1410,4 +1414,6 @@ subpaths
14101414
| webview.swift:119:10:119:10 | v2 | webview.swift:81:13:81:20 | call to source() : | webview.swift:119:10:119:10 | v2 | result |
14111415
| webview.swift:123:10:123:10 | v3 | webview.swift:81:13:81:20 | call to source() : | webview.swift:123:10:123:10 | v3 | result |
14121416
| webview.swift:133:10:133:10 | b | webview.swift:132:34:132:41 | call to source() : | webview.swift:133:10:133:10 | b | result |
1417+
| webview.swift:134:10:134:12 | .source | webview.swift:132:34:132:41 | call to source() : | webview.swift:134:10:134:12 | .source | result |
14131418
| webview.swift:138:10:138:10 | c | webview.swift:137:34:137:41 | call to source() : | webview.swift:138:10:138:10 | c | result |
1419+
| webview.swift:139:10:139:12 | .source | webview.swift:137:34:137:41 | call to source() : | webview.swift:139:10:139:12 | .source | result |

swift/ql/test/library-tests/dataflow/taint/webview.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ func testWKUserScript() {
131131

132132
let b = WKUserScript(source: source() as! String, injectionTime: atStart, forMainFrameOnly: false)
133133
sink(b) // $ tainted=132
134-
sink(b.source) // $ MISSING: tainted=132
134+
sink(b.source) // $ tainted=132
135135

136136
let world = WKContentWorld()
137137
let c = WKUserScript(source: source() as! String, injectionTime: atStart, forMainFrameOnly: false, in: world)
138138
sink(c) // $ tainted=137
139-
sink(c.source) // $ MISSING: tainted=137
139+
sink(c.source) // $ tainted=137
140140
}

0 commit comments

Comments
 (0)