@@ -11,6 +11,19 @@ private import codeql.rust.internal.TypeInference as TypeInference
1111private import codeql.rust.internal.Type as Type
1212private import codeql.rust.frameworks.stdlib.Builtins as Builtins
1313
14+ /**
15+ * Holds if the field `field` should, by default, be excluded from taint steps.
16+ * The syntax used to denote field is the same as `Field` for models as data.
17+ */
18+ extensible predicate excludeFieldTaintStep ( string field ) ;
19+
20+ private predicate excludedTaintStepContent ( Content c ) {
21+ exists ( string arg | excludeFieldTaintStep ( arg ) |
22+ FlowSummaryImpl:: encodeContentStructField ( c , arg ) or
23+ FlowSummaryImpl:: encodeContentTupleField ( c , arg )
24+ )
25+ }
26+
1427module RustTaintTracking implements InputSig< Location , RustDataFlow > {
1528 predicate defaultTaintSanitizer ( DataFlow:: Node node ) { none ( ) }
1629
@@ -48,13 +61,17 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
4861 // taint is propagated. We limit this to not apply if the type of the
4962 // operation is a small primitive type as these are often uninteresting
5063 // (for instance in the case of an injection query).
51- RustDataFlow:: readContentStep ( pred , _, succ ) and
52- not exists ( Struct s |
53- s = TypeInference:: inferType ( succ .asExpr ( ) ) .( Type:: StructType ) .getStruct ( )
54- |
55- s instanceof Builtins:: NumericType or
56- s instanceof Builtins:: Bool or
57- s instanceof Builtins:: Char
64+ exists ( Content c |
65+ RustDataFlow:: readContentStep ( pred , c , succ ) and
66+ forex ( Type:: Type t | t = TypeInference:: inferType ( succ .asExpr ( ) ) |
67+ not exists ( Struct s | s = t .( Type:: StructType ) .getStruct ( ) |
68+ s instanceof Builtins:: NumericType or
69+ s instanceof Builtins:: Bool or
70+ s instanceof Builtins:: Char
71+ )
72+ ) and
73+ not excludedTaintStepContent ( c ) and
74+ not TypeInference:: inferType ( succ .asExpr ( ) ) .( Type:: EnumType ) .getEnum ( ) .isFieldless ( )
5875 )
5976 or
6077 // Let all read steps (including those from flow summaries and those that
0 commit comments