Skip to content

Commit 0d8aa82

Browse files
committed
Swift: Use asNominalType() more widely to include things declared in extensions.
1 parent ccbd041 commit 0d8aa82

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ private class UrlLaunchOptionsRemoteFlowSource extends RemoteFlowSource {
4949
private class ApplicationWithLaunchOptionsFunc extends Function {
5050
ApplicationWithLaunchOptionsFunc() {
5151
this.getName() = "application(_:" + ["did", "will"] + "FinishLaunchingWithOptions:)" and
52-
this.getEnclosingDecl().(ClassOrStructDecl).getABaseTypeDecl*().(ProtocolDecl).getName() =
52+
this.getEnclosingDecl().asNominalTypeDecl().getABaseTypeDecl*().(ProtocolDecl).getName() =
5353
"UIApplicationDelegate"
5454
}
5555
}
5656

5757
private class LaunchOptionsUrlVarDecl extends VarDecl {
5858
LaunchOptionsUrlVarDecl() {
59-
this.getEnclosingDecl().(StructDecl).getFullName() = "UIApplication.LaunchOptionsKey" and
59+
this.getEnclosingDecl().asNominalTypeDecl().getFullName() = "UIApplication.LaunchOptionsKey" and
6060
this.getName() = "url"
6161
}
6262
}
@@ -68,7 +68,7 @@ private class UiOpenUrlContextUrlInheritTaint extends TaintInheritingContent,
6868
DataFlow::Content::FieldContent
6969
{
7070
UiOpenUrlContextUrlInheritTaint() {
71-
this.getField().getEnclosingDecl().(NominalTypeDecl).getName() = "UIOpenURLContext" and
71+
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "UIOpenURLContext" and
7272
this.getField().getName() = "url"
7373
}
7474
}
@@ -80,7 +80,7 @@ private class UserActivityUrlInheritTaint extends TaintInheritingContent,
8080
DataFlow::Content::FieldContent
8181
{
8282
UserActivityUrlInheritTaint() {
83-
this.getField().getEnclosingDecl().(NominalTypeDecl).getName() = "NSUserActivity" and
83+
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "NSUserActivity" and
8484
this.getField().getName() = "webpageURL"
8585
}
8686
}
@@ -93,7 +93,7 @@ private class ConnectionOptionsFieldsInheritTaint extends TaintInheritingContent
9393
DataFlow::Content::FieldContent
9494
{
9595
ConnectionOptionsFieldsInheritTaint() {
96-
this.getField().getEnclosingDecl().(NominalTypeDecl).getName() = "ConnectionOptions" and
96+
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "ConnectionOptions" and
9797
this.getField().getName() = ["userActivities", "urlContexts"]
9898
}
9999
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private class NsMutableDataSummaries extends SummaryModelCsv {
7575
private class NsDataTaintedFields extends TaintInheritingContent, DataFlow::Content::FieldContent {
7676
NsDataTaintedFields() {
7777
exists(FieldDecl f | this.getField() = f |
78-
f.getEnclosingDecl() instanceof NsData and
78+
f.getEnclosingDecl().asNominalTypeDecl() instanceof NsData and
7979
f.getName() = ["bytes", "description"]
8080
)
8181
}
@@ -87,7 +87,7 @@ private class NsMutableDataTaintedFields extends TaintInheritingContent,
8787
{
8888
NsMutableDataTaintedFields() {
8989
exists(FieldDecl f | this.getField() = f |
90-
f.getEnclosingDecl() instanceof NsMutableData and
90+
f.getEnclosingDecl().asNominalTypeDecl() instanceof NsMutableData and
9191
f.getName() = "mutableBytes"
9292
)
9393
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class UrlDecl extends StructDecl {
1616
* A content implying that, if a `URL` is tainted, then all its fields are tainted.
1717
*/
1818
private class UriFieldsInheritTaint extends TaintInheritingContent, DataFlow::Content::FieldContent {
19-
UriFieldsInheritTaint() { this.getField().getEnclosingDecl() instanceof UrlDecl }
19+
UriFieldsInheritTaint() {
20+
this.getField().getEnclosingDecl().asNominalTypeDecl() instanceof UrlDecl
21+
}
2022
}
2123

2224
/**
@@ -27,7 +29,7 @@ private class UrlRequestFieldsInheritTaint extends TaintInheritingContent,
2729
DataFlow::Content::FieldContent
2830
{
2931
UrlRequestFieldsInheritTaint() {
30-
this.getField().getEnclosingDecl().(NominalTypeDecl).getName() = "URLRequest" and
32+
this.getField().getEnclosingDecl().asNominalTypeDecl().getName() = "URLRequest" and
3133
this.getField().getName() =
3234
["url", "httpBody", "httpBodyStream", "mainDocument", "allHTTPHeaderFields"]
3335
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private class WKScriptMessageBodyInheritsTaint extends TaintInheritingContent,
3232
{
3333
WKScriptMessageBodyInheritsTaint() {
3434
exists(FieldDecl f | this.getField() = f |
35-
f.getEnclosingDecl() instanceof WKScriptMessageDecl and
35+
f.getEnclosingDecl().asNominalTypeDecl() instanceof WKScriptMessageDecl and
3636
f.getName() = "body"
3737
)
3838
}
@@ -170,16 +170,16 @@ private class JsExportedType extends ClassOrStructDecl {
170170
private class JsExportedSource extends RemoteFlowSource {
171171
JsExportedSource() {
172172
exists(Method adopter, Method base |
173-
base.getEnclosingDecl() instanceof JsExportedProto and
174-
adopter.getEnclosingDecl() instanceof JsExportedType
173+
base.getEnclosingDecl().asNominalTypeDecl() instanceof JsExportedProto and
174+
adopter.getEnclosingDecl().asNominalTypeDecl() instanceof JsExportedType
175175
|
176176
this.(DataFlow::ParameterNode).getParameter().getDeclaringFunction() = adopter and
177177
pragma[only_bind_out](adopter.getName()) = pragma[only_bind_out](base.getName())
178178
)
179179
or
180180
exists(FieldDecl adopter, FieldDecl base |
181-
base.getEnclosingDecl() instanceof JsExportedProto and
182-
adopter.getEnclosingDecl() instanceof JsExportedType
181+
base.getEnclosingDecl().asNominalTypeDecl() instanceof JsExportedProto and
182+
adopter.getEnclosingDecl().asNominalTypeDecl() instanceof JsExportedType
183183
|
184184
this.asExpr().(MemberRefExpr).getMember() = adopter and
185185
pragma[only_bind_out](adopter.getName()) = pragma[only_bind_out](base.getName())
@@ -210,7 +210,7 @@ private class WKUserScriptInheritsTaint extends TaintInheritingContent,
210210
{
211211
WKUserScriptInheritsTaint() {
212212
exists(FieldDecl f | this.getField() = f |
213-
f.getEnclosingDecl().(ClassOrStructDecl).getName() = "WKUserScript" and
213+
f.getEnclosingDecl().asNominalTypeDecl().getName() = "WKUserScript" and
214214
f.getName() = "source"
215215
)
216216
}

swift/ql/lib/codeql/swift/frameworks/Xml/AEXML.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import swift
77
/** The creation of an `AEXMLParser`. */
88
class AexmlParser extends ApplyExpr {
99
AexmlParser() {
10-
this.getStaticTarget().(Initializer).getEnclosingDecl() instanceof AexmlParserDecl
10+
this.getStaticTarget().(Initializer).getEnclosingDecl().asNominalTypeDecl() instanceof
11+
AexmlParserDecl
1112
}
1213
}
1314

1415
/** The creation of an `AEXMLDocument`. */
1516
class AexmlDocument extends ApplyExpr {
1617
AexmlDocument() {
17-
this.getStaticTarget().(Initializer).getEnclosingDecl() instanceof AexmlDocumentDecl
18+
this.getStaticTarget().(Initializer).getEnclosingDecl().asNominalTypeDecl() instanceof
19+
AexmlDocumentDecl
1820
}
1921
}
2022

@@ -24,7 +26,7 @@ class AexmlDocumentLoadXml extends MethodApplyExpr {
2426
exists(Method f |
2527
this.getStaticTarget() = f and
2628
f.hasName("loadXML(_:)") and
27-
f.getEnclosingDecl() instanceof AexmlDocumentDecl
29+
f.getEnclosingDecl().asNominalTypeDecl() instanceof AexmlDocumentDecl
2830
)
2931
}
3032
}
@@ -44,7 +46,7 @@ class AexmlShouldResolveExternalEntities extends MemberRefExpr {
4446
AexmlShouldResolveExternalEntities() {
4547
exists(FieldDecl f | this.getMember() = f |
4648
f.getName() = "shouldResolveExternalEntities" and
47-
f.getEnclosingDecl().(NominalTypeDecl).getType() instanceof AexmlOptionsParserSettingsType
49+
f.getEnclosingDecl().asNominalTypeDecl().getType() instanceof AexmlOptionsParserSettingsType
4850
)
4951
}
5052
}

swift/ql/lib/codeql/swift/security/CleartextLoggingExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private class OsLogPrivacyRef extends MemberRefExpr {
6464

6565
OsLogPrivacyRef() {
6666
exists(FieldDecl f | this.getMember() = f |
67-
f.getEnclosingDecl().(NominalTypeDecl).getName() = "OSLogPrivacy" and
67+
f.getEnclosingDecl().asNominalTypeDecl().getName() = "OSLogPrivacy" and
6868
optionName = f.getName()
6969
)
7070
}

swift/ql/lib/codeql/swift/security/PathInjectionExtensions.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ private class DefaultPathInjectionBarrier extends PathInjectionBarrier {
3838
// This is a simplified implementation.
3939
exists(CallExpr starts, CallExpr normalize, DataFlow::Node validated |
4040
starts.getStaticTarget().getName() = "starts(with:)" and
41-
starts.getStaticTarget().getEnclosingDecl() instanceof FilePath and
41+
starts.getStaticTarget().getEnclosingDecl().asNominalTypeDecl() instanceof FilePath and
4242
normalize.getStaticTarget().getName() = "lexicallyNormalized()" and
43-
normalize.getStaticTarget().getEnclosingDecl() instanceof FilePath
43+
normalize.getStaticTarget().getEnclosingDecl().asNominalTypeDecl() instanceof FilePath
4444
|
4545
TaintTracking::localTaint(validated, DataFlow::exprNode(normalize.getQualifier())) and
4646
DataFlow::localExprFlow(normalize, starts.getQualifier()) and

swift/ql/lib/codeql/swift/security/XXEExtensions.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private class XmlDocumentXxeSink extends XxeSink {
8080
/** An `XMLDocument` that sets `nodeLoadExternalEntitiesAlways` in its options. */
8181
private class VulnerableXmlDocument extends ApplyExpr {
8282
VulnerableXmlDocument() {
83-
this.getStaticTarget().(Initializer).getEnclosingDecl().(NominalTypeDecl).getFullName() =
83+
this.getStaticTarget().(Initializer).getEnclosingDecl().asNominalTypeDecl().getFullName() =
8484
"XMLDocument" and
8585
this.getArgument(1).getExpr().(ArrayExpr).getAnElement().(MemberRefExpr).getMember() instanceof
8686
NodeLoadExternalEntitiesAlways
@@ -91,7 +91,7 @@ private class VulnerableXmlDocument extends ApplyExpr {
9191
private class NodeLoadExternalEntitiesAlways extends VarDecl {
9292
NodeLoadExternalEntitiesAlways() {
9393
this.getName() = "nodeLoadExternalEntitiesAlways" and
94-
this.getEnclosingDecl().(StructDecl).getFullName() = "XMLNode.Options"
94+
this.getEnclosingDecl().asNominalTypeDecl().(StructDecl).getFullName() = "XMLNode.Options"
9595
}
9696
}
9797

0 commit comments

Comments
 (0)