1111 */
1212
1313import go
14- import DataFlow:: PathGraph
1514
1615/** The `ssh.InsecureIgnoreHostKey` function, which allows connecting to any host regardless of its host key. */
1716class InsecureIgnoreHostKey extends Function {
@@ -55,45 +54,44 @@ class InsecureHostKeyCallbackFunc extends HostKeyCallbackFunc {
5554 }
5655}
5756
58- /**
59- * A data-flow configuration for identifying `HostKeyCallbackFunc` instances that reach `ClientConfig.HostKeyCallback` fields.
60- */
61- class HostKeyCallbackAssignmentConfig extends DataFlow:: Configuration {
62- HostKeyCallbackAssignmentConfig ( ) { this = "HostKeyCallbackAssignmentConfig" }
63-
64- override predicate isSource ( DataFlow:: Node source ) { source instanceof HostKeyCallbackFunc }
57+ module Config implements DataFlow:: ConfigSig {
58+ predicate isSource ( DataFlow:: Node source ) { source instanceof HostKeyCallbackFunc }
6559
6660 /**
6761 * Holds if `sink` is a value written by `write` to a field `ClientConfig.HostKeyCallback`.
6862 */
69- predicate writeIsSink ( DataFlow:: Node sink , Write write ) {
63+ additional predicate writeIsSink ( DataFlow:: Node sink , Write write ) {
7064 exists ( Field f |
7165 f .hasQualifiedName ( CryptoSsh:: packagePath ( ) , "ClientConfig" , "HostKeyCallback" ) and
7266 write .writesField ( _, f , sink )
7367 )
7468 }
7569
76- override predicate isSink ( DataFlow:: Node sink ) { this . writeIsSink ( sink , _) }
70+ predicate isSink ( DataFlow:: Node sink ) { writeIsSink ( sink , _) }
7771}
7872
73+ module Flow = DataFlow:: Global< Config > ;
74+
75+ import Flow:: PathGraph
76+
7977/**
8078 * Holds if a secure host-check function reaches `sink` or another similar sink.
8179 *
8280 * A sink is considered similar if it writes to the same variable and field.
8381 */
84- predicate hostCheckReachesSink ( DataFlow :: PathNode sink ) {
85- exists ( HostKeyCallbackAssignmentConfig config , DataFlow :: PathNode source |
82+ predicate hostCheckReachesSink ( Flow :: PathNode sink ) {
83+ exists ( Flow :: PathNode source |
8684 not source .getNode ( ) instanceof InsecureHostKeyCallbackFunc and
8785 (
88- config . hasFlowPath ( source , sink )
86+ Flow :: flowPath ( source , sink )
8987 or
9088 exists (
91- DataFlow :: PathNode otherSink , Write sinkWrite , Write otherSinkWrite ,
89+ Flow :: PathNode otherSink , Write sinkWrite , Write otherSinkWrite ,
9290 SsaWithFields sinkAccessPath , SsaWithFields otherSinkAccessPath
9391 |
94- config . hasFlowPath ( source , otherSink ) and
95- config . writeIsSink ( sink .getNode ( ) , sinkWrite ) and
96- config . writeIsSink ( otherSink .getNode ( ) , otherSinkWrite ) and
92+ Flow :: flowPath ( source , otherSink ) and
93+ Config :: writeIsSink ( sink .getNode ( ) , sinkWrite ) and
94+ Config :: writeIsSink ( otherSink .getNode ( ) , otherSinkWrite ) and
9795 sinkWrite .writesField ( sinkAccessPath .getAUse ( ) , _, sink .getNode ( ) ) and
9896 otherSinkWrite .writesField ( otherSinkAccessPath .getAUse ( ) , _, otherSink .getNode ( ) ) and
9997 otherSinkAccessPath = sinkAccessPath .similar ( )
@@ -102,9 +100,9 @@ predicate hostCheckReachesSink(DataFlow::PathNode sink) {
102100 )
103101}
104102
105- from HostKeyCallbackAssignmentConfig config , DataFlow :: PathNode source , DataFlow :: PathNode sink
103+ from Flow :: PathNode source , Flow :: PathNode sink
106104where
107- config . hasFlowPath ( source , sink ) and
105+ Flow :: flowPath ( source , sink ) and
108106 source .getNode ( ) instanceof InsecureHostKeyCallbackFunc and
109107 // Exclude cases where a good access-path function reaches the same or a similar sink
110108 // (these probably indicate optional host-checking)
0 commit comments