@@ -4,6 +4,7 @@ import swift
44private import codeql.swift.dataflow.DataFlow
55private import codeql.swift.dataflow.ExternalFlow
66private import codeql.swift.security.SensitiveExprs
7+ private import codeql.swift.StringFormat
78
89/** A data flow sink for cleartext logging of sensitive data vulnerabilities. */
910abstract class CleartextLoggingSink extends DataFlow:: Node { }
@@ -93,6 +94,48 @@ private class CleartextLoggingFieldAdditionalFlowStep extends CleartextLoggingAd
9394 }
9495}
9596
97+ /**
98+ * A sink that appears to be an imported C `printf` variant.
99+ */
100+ private class PrintfCleartextLoggingSink extends CleartextLoggingSink {
101+ PrintfCleartextLoggingSink ( ) {
102+ exists ( CallExpr ce , PrintfFormat f |
103+ ce .getStaticTarget ( ) = f and
104+ (
105+ this .asExpr ( ) = ce .getArgument ( f .getFormatParameterIndex ( ) ) .getExpr ( ) or
106+ this .asExpr ( ) = ce .getArgument ( f .getNumberOfParams ( ) - 1 ) .getExpr ( )
107+ ) and
108+ not f .isSprintf ( )
109+ )
110+ }
111+ }
112+
113+ /**
114+ * Holds if `label` looks like the name of a logging function.
115+ */
116+ bindingset [ label]
117+ private predicate logLikeHeuristic ( string label ) {
118+ label .regexpMatch ( "(l|.*L)og([A-Z0-9].*)?" ) // e.g. "logMessage", "debugLog"
119+ }
120+
121+ /**
122+ * A cleartext logging sink that is determined by imprecise methods.
123+ */
124+ class HeuristicCleartextLoggingSink extends CleartextLoggingSink {
125+ HeuristicCleartextLoggingSink ( ) {
126+ exists ( CallExpr ce , Function f , Expr e |
127+ (
128+ logLikeHeuristic ( f .getShortName ( ) ) or
129+ logLikeHeuristic ( f .getDeclaringDecl ( ) .( NominalTypeDecl ) .getName ( ) )
130+ ) and
131+ ce .getStaticTarget ( ) = f and
132+ ce .getAnArgument ( ) .getExpr ( ) = e and
133+ e .getType ( ) .getUnderlyingType ( ) .getName ( ) = [ "String" , "NSString" ] and
134+ this .asExpr ( ) = e
135+ )
136+ }
137+ }
138+
96139private class LoggingSinks extends SinkModelCsv {
97140 override predicate row ( string row ) {
98141 row =
@@ -123,6 +166,8 @@ private class LoggingSinks extends SinkModelCsv {
123166 ";;false;os_log(_:log:_:);;;Argument[2];log-injection" ,
124167 ";;false;os_log(_:dso:log:_:_:);;;Argument[0,4];log-injection" ,
125168 ";;false;os_log(_:dso:log:type:_:);;;Argument[0,4];log-injection" ,
169+ ";NSException;true;init(name:reason:userInfo:);;;Argument[1];log-injection" ,
170+ ";NSException;true;raise(_:format:arguments:);;;Argument[1..2];log-injection" ,
126171 ]
127172 }
128173}
0 commit comments