Skip to content

Swift: Use TaintInheritingContent in WebView.qll #14772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,15 @@ private class WKNavigationDelegateSource extends RemoteFlowSource {
}

/**
* A taint step implying that, if a `WKNavigationAction` is tainted, its `request` field is also tainted.
* A content implying that, if a `WKNavigationAction` is tainted, its
* `request` field is also tainted.
*/
private class WKNavigationActionTaintStep extends AdditionalTaintStep {
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
exists(MemberRefExpr e, Expr self, VarDecl member |
self.getType().getName() = "WKNavigationAction" and
member.getName() = "request"
|
e.getBase() = self and
e.getMember() = member and
n1.asExpr() = self and
n2.asExpr() = e
)
private class UrlRequestFieldsInheritTaint extends TaintInheritingContent,
DataFlow::Content::FieldContent
{
UrlRequestFieldsInheritTaint() {
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "WKNavigationAction" and
this.getField().getName() = "request"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct URLRequest {}

// --- tests ---

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

func testInheritBodyTaint() {
Expand Down Expand Up @@ -146,6 +146,9 @@ func testWKUserScript() {
}

func testWKNavigationAction() {
let src = source() as! WKNavigationAction
sink(src.request) // $ tainted=149
}
let src = source("WKNavigationAction") as! WKNavigationAction
sink(src.request) // $ tainted=WKNavigationAction

let keypath = \WKNavigationAction.request
sink(src[keyPath: keypath]) // $ tainted=WKNavigationAction
}