|
1 | 1 | import swift
|
| 2 | +private import codeql.swift.dataflow.DataFlow |
2 | 3 | private import codeql.swift.dataflow.ExternalFlow
|
| 4 | +private import codeql.swift.dataflow.FlowSources |
3 | 5 |
|
4 | 6 | private class UrlRemoteFlowSource extends SourceModelCsv {
|
5 | 7 | override predicate row(string row) {
|
6 | 8 | row =
|
7 | 9 | [
|
8 | 10 | ";UIApplicationDelegate;true;application(_:open:options:);;;Parameter[1];remote",
|
9 | 11 | ";UIApplicationDelegate;true;application(_:handleOpen:);;;Parameter[1];remote",
|
10 |
| - ";UIApplicationDelegate;true;application(_:open:sourceApplication:annotation:);;;Parameter[1];remote" |
| 12 | + ";UIApplicationDelegate;true;application(_:open:sourceApplication:annotation:);;;Parameter[1];remote", |
| 13 | + // TODO: The actual source is the value of `UIApplication.LaunchOptionsKey.url` in the launchOptions dictionary. |
| 14 | + // Use dictionary value contents when available. |
| 15 | + // ";UIApplicationDelegate;true;application(_:didFinishLaunchingWithOptions:);;;Parameter[1].MapValue;remote", |
| 16 | + // ";UIApplicationDelegate;true;application(_:willFinishLaunchingWithOptions:);;;Parameter[1].MapValue;remote" |
11 | 17 | ]
|
12 | 18 | }
|
13 | 19 | }
|
| 20 | + |
| 21 | +/** |
| 22 | + * A read of `UIApplication.LaunchOptionsKey.url` on a dictionary received in |
| 23 | + * `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)` or |
| 24 | + * `UIApplicationDelegate.application(_:willFinishLaunchingWithOptions:)`. |
| 25 | + */ |
| 26 | +// This is a temporary workaround until the TODO above is addressed. |
| 27 | +private class UrlLaunchOptionsRemoteFlowSource extends RemoteFlowSource { |
| 28 | + UrlLaunchOptionsRemoteFlowSource() { |
| 29 | + exists(ApllicationWithLaunchOptionsFunc f, SubscriptExpr e | |
| 30 | + DataFlow::localExprFlow(f.getParam(1).getAnAccess(), e.getBase()) and |
| 31 | + e.getAnArgument().getExpr().(MemberRefExpr).getMember() instanceof LaunchOptionsUrlVarDecl and |
| 32 | + this.asExpr() = e |
| 33 | + ) |
| 34 | + } |
| 35 | + |
| 36 | + override string getSourceType() { |
| 37 | + result = "Remote URL in UIApplicationDelegate.application.launchOptions" |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +private class ApllicationWithLaunchOptionsFunc extends FuncDecl { |
| 42 | + ApllicationWithLaunchOptionsFunc() { |
| 43 | + this.getName() = "application(_:" + ["did", "will"] + "FinishLaunchingWithOptions:)" and |
| 44 | + this.getEnclosingDecl().(ClassOrStructDecl).getABaseTypeDecl*().(ProtocolDecl).getName() = |
| 45 | + "UIApplicationDelegate" |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +private class LaunchOptionsUrlVarDecl extends VarDecl { |
| 50 | + LaunchOptionsUrlVarDecl() { |
| 51 | + this.getEnclosingDecl().(StructDecl).getName() = "UIApplication.LaunchOptionsKey" and |
| 52 | + this.getName() = "url" |
| 53 | + } |
| 54 | +} |
0 commit comments