4
4
5
5
import java
6
6
import semmle.code.java.dataflow.DataFlow
7
- import semmle.code.java.dataflow.DataFlow2
8
- import semmle.code.java.dataflow.DataFlow3
9
7
10
8
/**
11
9
* The class `org.yaml.snakeyaml.constructor.SafeConstructor`.
@@ -30,28 +28,28 @@ class Yaml extends RefType {
30
28
Yaml ( ) { this .getAnAncestor ( ) .hasQualifiedName ( "org.yaml.snakeyaml" , "Yaml" ) }
31
29
}
32
30
33
- private class SafeYamlConstructionFlowConfig extends DataFlow3 :: Configuration {
34
- SafeYamlConstructionFlowConfig ( ) { this = "SnakeYaml::SafeYamlConstructionFlowConfig" }
31
+ private module SafeYamlConstructionFlowConfig implements DataFlow :: ConfigSig {
32
+ predicate isSource ( DataFlow :: Node src ) { src . asExpr ( ) instanceof SafeSnakeYamlConstruction }
35
33
36
- override predicate isSource ( DataFlow:: Node src ) {
37
- src .asExpr ( ) instanceof SafeSnakeYamlConstruction
38
- }
39
-
40
- override predicate isSink ( DataFlow:: Node sink ) { sink = this .yamlClassInstanceExprArgument ( _) }
34
+ predicate isSink ( DataFlow:: Node sink ) { sink = yamlClassInstanceExprArgument ( _) }
41
35
42
- private DataFlow:: ExprNode yamlClassInstanceExprArgument ( ClassInstanceExpr cie ) {
36
+ additional DataFlow:: ExprNode yamlClassInstanceExprArgument ( ClassInstanceExpr cie ) {
43
37
cie .getConstructedType ( ) instanceof Yaml and
44
38
result .getExpr ( ) = cie .getArgument ( 0 )
45
39
}
46
40
47
- ClassInstanceExpr getSafeYaml ( ) { this .hasFlowTo ( this .yamlClassInstanceExprArgument ( result ) ) }
41
+ additional ClassInstanceExpr getSafeYaml ( ) {
42
+ SafeYamlConstructionFlow:: flowTo ( yamlClassInstanceExprArgument ( result ) )
43
+ }
48
44
}
49
45
46
+ private module SafeYamlConstructionFlow = DataFlow:: Global< SafeYamlConstructionFlowConfig > ;
47
+
50
48
/**
51
49
* An instance of `Yaml` that does not allow arbitrary constructor to be called.
52
50
*/
53
51
private class SafeYaml extends ClassInstanceExpr {
54
- SafeYaml ( ) { exists ( SafeYamlConstructionFlowConfig conf | conf . getSafeYaml ( ) = this ) }
52
+ SafeYaml ( ) { SafeYamlConstructionFlowConfig:: getSafeYaml ( ) = this }
55
53
}
56
54
57
55
/** A call to a parse method of `Yaml`. */
@@ -65,23 +63,25 @@ private class SnakeYamlParse extends MethodAccess {
65
63
}
66
64
}
67
65
68
- private class SafeYamlFlowConfig extends DataFlow2 :: Configuration {
69
- SafeYamlFlowConfig ( ) { this = "SnakeYaml::SafeYamlFlowConfig" }
66
+ private module SafeYamlFlowConfig implements DataFlow :: ConfigSig {
67
+ predicate isSource ( DataFlow :: Node src ) { src . asExpr ( ) instanceof SafeYaml }
70
68
71
- override predicate isSource ( DataFlow:: Node src ) { src . asExpr ( ) instanceof SafeYaml }
69
+ predicate isSink ( DataFlow:: Node sink ) { sink = yamlParseQualifier ( _ ) }
72
70
73
- override predicate isSink ( DataFlow:: Node sink ) { sink = this .yamlParseQualifier ( _) }
74
-
75
- private DataFlow:: ExprNode yamlParseQualifier ( SnakeYamlParse syp ) {
71
+ additional DataFlow:: ExprNode yamlParseQualifier ( SnakeYamlParse syp ) {
76
72
result .getExpr ( ) = syp .getQualifier ( )
77
73
}
78
74
79
- SnakeYamlParse getASafeSnakeYamlParse ( ) { this .hasFlowTo ( this .yamlParseQualifier ( result ) ) }
75
+ additional SnakeYamlParse getASafeSnakeYamlParse ( ) {
76
+ SafeYamlFlow:: flowTo ( yamlParseQualifier ( result ) )
77
+ }
80
78
}
81
79
80
+ private module SafeYamlFlow = DataFlow:: Global< SafeYamlFlowConfig > ;
81
+
82
82
/**
83
83
* A call to a parse method of `Yaml` that allows arbitrary constructor to be called.
84
84
*/
85
85
class UnsafeSnakeYamlParse extends SnakeYamlParse {
86
- UnsafeSnakeYamlParse ( ) { not exists ( SafeYamlFlowConfig sy | sy . getASafeSnakeYamlParse ( ) = this ) }
86
+ UnsafeSnakeYamlParse ( ) { not SafeYamlFlowConfig:: getASafeSnakeYamlParse ( ) = this }
87
87
}
0 commit comments