11import java
22import semmle.code.java.dataflow.FlowSources
3- import semmle.code.java.dataflow.TaintTracking2
43import DataFlow
54
65/**
@@ -26,140 +25,22 @@ class SetRevocationEnabledSink extends DataFlow::ExprNode {
2625 exists ( MethodAccess setRevocationEnabledCall |
2726 setRevocationEnabledCall .getMethod ( ) instanceof SetRevocationEnabledMethod and
2827 setRevocationEnabledCall .getArgument ( 0 ) = getExpr ( ) and
29- not exists (
30- SettingRevocationCheckerConfig config , DataFlow2:: PathNode source , DataFlow2:: PathNode sink
31- |
32- config .hasFlowPath ( source , sink ) and
33- sink .getNode ( ) .( SettingRevocationCheckerSink ) .getVariable ( ) =
28+ not exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
29+ ( m instanceof AddCertPathCheckerMethod or m instanceof SetCertPathCheckersMethod ) and
30+ ma .getQualifier ( ) .( VarAccess ) .getVariable ( ) =
3431 setRevocationEnabledCall .getQualifier ( ) .( VarAccess ) .getVariable ( )
3532 )
3633 )
3734 }
3835}
3936
40- /**
41- * A dataflow config for tracking a custom revocation checker.
42- */
43- class SettingRevocationCheckerConfig extends DataFlow2:: Configuration {
44- SettingRevocationCheckerConfig ( ) {
45- this = "DisabledRevocationChecking::SettingRevocationCheckerConfig"
46- }
47-
48- override predicate isSource ( DataFlow:: Node source ) {
49- source instanceof GetRevocationCheckerSource
50- }
51-
52- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof SettingRevocationCheckerSink }
53-
54- override predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
55- createSingletonListStep ( node1 , node2 ) or
56- createListOfElementsStep ( node1 , node2 ) or
57- convertArrayToListStep ( node1 , node2 ) or
58- addToListStep ( node1 , node2 )
59- }
60-
61- override int fieldFlowBranchLimit ( ) { result = 0 }
62- }
63-
64- /**
65- * A source that creates a custom revocation checker,
66- * i.e. `CertPathValidator.getRevocationChecker()`.
67- */
68- class GetRevocationCheckerSource extends DataFlow:: ExprNode {
69- GetRevocationCheckerSource ( ) {
70- exists ( MethodAccess ma | ma .getMethod ( ) instanceof GetRevocationCheckerMethod |
71- ma = asExpr ( ) or ma .getQualifier ( ) = asExpr ( )
72- )
73- }
74- }
75-
76- /**
77- * A sink that sets a custom revocation checker in `PKIXParameters`,
78- * i.e. `PKIXParameters.addCertPathChecker()` or `PKIXParameters.setCertPathCheckers()`.
79- */
80- class SettingRevocationCheckerSink extends DataFlow:: ExprNode {
81- MethodAccess ma ;
82-
83- SettingRevocationCheckerSink ( ) {
84- (
85- ma .getMethod ( ) instanceof AddCertPathCheckerMethod or
86- ma .getMethod ( ) instanceof SetCertPathCheckersMethod
87- ) and
88- ma .getArgument ( 0 ) = asExpr ( )
89- }
90-
91- Variable getVariable ( ) { result = ma .getQualifier ( ) .( VarAccess ) .getVariable ( ) }
92- }
93-
94- /**
95- * Holds if `node1` to `node2` is a dataflow step that creates a singleton list,
96- * i.e. `Collections.singletonList(element)`.
97- */
98- predicate createSingletonListStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
99- exists ( StaticMethodAccess ma , Method m | m = ma .getMethod ( ) |
100- m .getDeclaringType ( ) instanceof Collections and
101- m .hasName ( "singletonList" ) and
102- ma .getArgument ( 0 ) = node1 .asExpr ( ) and
103- ma = node2 .asExpr ( )
104- )
105- }
106-
107- /**
108- * Holds if `node1` to `node2` is a dataflow step that converts an array to a list
109- * i.e. `Arrays.asList(element)`.
110- */
111- predicate convertArrayToListStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
112- exists ( StaticMethodAccess ma , Method m | m = ma .getMethod ( ) |
113- m .getDeclaringType ( ) instanceof Arrays and
114- m .hasName ( "asList" ) and
115- ma .getArgument ( 0 ) = node1 .asExpr ( ) and
116- ma = node2 .asExpr ( )
117- )
118- }
119-
120- /**
121- * Holds if `node1` to `node2` is a dataflow step that adds an element to a list,
122- * i.e. `list.add(element)` or `list.addAll(elements)`.
123- */
124- predicate addToListStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
125- exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
126- m .getDeclaringType ( ) instanceof List and
127- (
128- m .hasName ( "add" ) or
129- m .hasName ( "addAll" )
130- ) and
131- ma .getArgument ( 0 ) = node1 .asExpr ( ) and
132- ma .getQualifier ( ) = node2 .asExpr ( )
133- )
134- }
135-
136- /**
137- * Holds if `node1` to `node2` is a dataflow step that creates a list,
138- * i.e. `List.of(element)`.
139- */
140- predicate createListOfElementsStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
141- exists ( StaticMethodAccess ma , Method m | m = ma .getMethod ( ) |
142- m .getDeclaringType ( ) instanceof List and
143- m .hasName ( "of" ) and
144- ma .getAnArgument ( ) = node1 .asExpr ( ) and
145- ma = node2 .asExpr ( )
146- )
147- }
148-
14937class SetRevocationEnabledMethod extends Method {
15038 SetRevocationEnabledMethod ( ) {
15139 getDeclaringType ( ) instanceof PKIXParameters and
15240 hasName ( "setRevocationEnabled" )
15341 }
15442}
15543
156- class GetRevocationCheckerMethod extends Method {
157- GetRevocationCheckerMethod ( ) {
158- getDeclaringType ( ) instanceof CertPathValidator and
159- hasName ( "getRevocationChecker" )
160- }
161- }
162-
16344class AddCertPathCheckerMethod extends Method {
16445 AddCertPathCheckerMethod ( ) {
16546 getDeclaringType ( ) instanceof PKIXParameters and
@@ -177,22 +58,3 @@ class SetCertPathCheckersMethod extends Method {
17758class PKIXParameters extends RefType {
17859 PKIXParameters ( ) { hasQualifiedName ( "java.security.cert" , "PKIXParameters" ) }
17960}
180-
181- class CertPathValidator extends RefType {
182- CertPathValidator ( ) { hasQualifiedName ( "java.security.cert" , "CertPathValidator" ) }
183- }
184-
185- class Collections extends RefType {
186- Collections ( ) { hasQualifiedName ( "java.util" , "Collections" ) }
187- }
188-
189- class Arrays extends RefType {
190- Arrays ( ) { hasQualifiedName ( "java.util" , "Arrays" ) }
191- }
192-
193- class List extends RefType {
194- List ( ) {
195- this .hasQualifiedName ( "java.util" , "List<>" ) or
196- this .( ParameterizedInterface ) .getGenericType ( ) .hasQualifiedName ( "java.util" , "List" )
197- }
198- }
0 commit comments