1+ /**
2+ * LogSanitizer.qll
3+ *
4+ * Predicates to identify sanitizer functions and zap encoder-like types.
5+ * Template: adjust whitelist entries as needed.
6+ */
7+
8+ import go
9+
10+ /**
11+ * isKnownSanitizer(Function f)
12+ * - True for explicit sanitizer functions (add fully-qualified names as needed).
13+ */
14+ predicate isKnownSanitizer ( Function f ) {
15+ exists ( string fullname |
16+ fullname = f .getDeclaringType ( ) .getPackage ( ) .getName ( ) + "." + f .getName ( ) and
17+ (
18+ fullname = "github.com/myorg/mylib.EscapeForLog" or
19+ fullname = "github.com/myorg/mylib.SanitizeForZap"
20+ )
21+ )
22+ }
23+
24+ /**
25+ * isZapEncoderLike(Type t)
26+ * - True for types that implement go.uber.org/zap/zapcore.Encoder
27+ * - If you prefer explicit whitelisting, replace/extend this predicate.
28+ */
29+ predicate isZapEncoderLike ( Type t ) {
30+ exists ( InterfaceType it |
31+ it .getPackage ( ) .getName ( ) = "go.uber.org/zap/zapcore" and
32+ it .getName ( ) = "Encoder" and
33+ t .implementsInterface ( it )
34+ )
35+ }
36+
37+ /**
38+ * isFlowThroughZapEncoder(Function f)
39+ * - True for functions/methods that act on encoder types (AddString, Encode, etc.)
40+ */
41+ predicate isFlowThroughZapEncoder ( Function f ) {
42+ exists ( Type recv |
43+ f .getDeclaringType ( ) = recv and
44+ isZapEncoderLike ( recv )
45+ )
46+ or
47+ (
48+ f .getName ( ) = "AddString" or
49+ f .getName ( ) = "AddStringer" or
50+ f .getName ( ) = "AddReflected" or
51+ f .getName ( ) = "EncodeEntry" or
52+ f .getName ( ) = "Encode"
53+ )
54+ }
55+
56+ /**
57+ * isSanitizer(Function f)
58+ * - Top-level predicate used by queries to test for sanitization steps.
59+ */
60+ predicate isSanitizer ( Function f ) {
61+ isKnownSanitizer ( f ) or isFlowThroughZapEncoder ( f )
62+ }
0 commit comments