Skip to content

Commit 0342b3e

Browse files
authored
Merge pull request #14772 from geoffw0/webview
Swift: Use TaintInheritingContent in WebView.qll
2 parents d28e792 + 463096e commit 0342b3e

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,15 @@ private class WKNavigationDelegateSource extends RemoteFlowSource {
7474
}
7575

7676
/**
77-
* A taint step implying that, if a `WKNavigationAction` is tainted, its `request` field is also tainted.
77+
* A content implying that, if a `WKNavigationAction` is tainted, its
78+
* `request` field is also tainted.
7879
*/
79-
private class WKNavigationActionTaintStep extends AdditionalTaintStep {
80-
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
81-
exists(MemberRefExpr e, Expr self, VarDecl member |
82-
self.getType().getName() = "WKNavigationAction" and
83-
member.getName() = "request"
84-
|
85-
e.getBase() = self and
86-
e.getMember() = member and
87-
n1.asExpr() = self and
88-
n2.asExpr() = e
89-
)
80+
private class UrlRequestFieldsInheritTaint extends TaintInheritingContent,
81+
DataFlow::Content::FieldContent
82+
{
83+
UrlRequestFieldsInheritTaint() {
84+
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "WKNavigationAction" and
85+
this.getField().getName() = "request"
9086
}
9187
}
9288

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct URLRequest {}
7676

7777
// --- tests ---
7878

79-
func source() -> Any { return "" }
79+
func source(_ label: String? = "") -> Any { return "" }
8080
func sink(_: Any) {}
8181

8282
func testInheritBodyTaint() {
@@ -146,6 +146,9 @@ func testWKUserScript() {
146146
}
147147

148148
func testWKNavigationAction() {
149-
let src = source() as! WKNavigationAction
150-
sink(src.request) // $ tainted=149
151-
}
149+
let src = source("WKNavigationAction") as! WKNavigationAction
150+
sink(src.request) // $ tainted=WKNavigationAction
151+
152+
let keypath = \WKNavigationAction.request
153+
sink(src[keyPath: keypath]) // $ tainted=WKNavigationAction
154+
}

0 commit comments

Comments
 (0)