Skip to content

Commit 3716d67

Browse files
authored
Merge pull request github#11451 from geoffw0/wkuserscript
Swift: models for WKUserScript
2 parents f291320 + 30468dd commit 3716d67

File tree

6 files changed

+420
-319
lines changed

6 files changed

+420
-319
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,29 @@ private class JsExportedSource extends RemoteFlowSource {
131131

132132
override string getSourceType() { result = "Member of a type exposed through JSExport" }
133133
}
134+
135+
/**
136+
* A model for `WKUserScript` summaries.
137+
*/
138+
private class WKUserScriptSummaries extends SummaryModelCsv {
139+
override predicate row(string row) {
140+
row =
141+
[
142+
";WKUserScript;true;init(source:injectionTime:forMainFrameOnly:);;;Argument[0];ReturnValue;taint",
143+
";WKUserScript;true;init(source:injectionTime:forMainFrameOnly:in:);;;Argument[0];ReturnValue;taint"
144+
]
145+
}
146+
}
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/src/queries/Security/CWE-094/UnsafeJsEval.ql

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ class UnsafeJsEvalConfig extends TaintTracking::Configuration {
9696
// TODO: convert to new taint flow models
9797
override predicate isAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
9898
exists(Argument arg |
99-
arg =
100-
any(CallExpr ce |
101-
ce.getStaticTarget()
102-
.(MethodDecl)
103-
.hasQualifiedName("WKUserScript",
104-
[
105-
"init(source:injectionTime:forMainFrameOnly:)",
106-
"init(source:injectionTime:forMainFrameOnly:in:)"
107-
])
108-
).getArgument(0)
109-
or
11099
arg =
111100
any(CallExpr ce |
112101
ce.getStaticTarget().(MethodDecl).hasQualifiedName("String", "init(decoding:as:)")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,7 @@
165165
| url.swift:100:12:100:54 | ...! | url.swift:100:12:100:56 | .standardizedFileURL |
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 |
168-
| webview.swift:52:11:52:18 | call to source() | webview.swift:52:10:52:41 | .body |
168+
| 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 |

0 commit comments

Comments
 (0)