File tree Expand file tree Collapse file tree 2 files changed +32
-13
lines changed
ruby/ql/lib/codeql/ruby/security Expand file tree Collapse file tree 2 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,13 @@ module CodeInjection {
39
39
/**
40
40
* A sanitizer for "Code injection" vulnerabilities.
41
41
*/
42
- abstract class Sanitizer extends DataFlow:: Node { }
42
+ abstract class Sanitizer extends DataFlow:: Node {
43
+ /**
44
+ * Gets a flow state for which this is a sanitizer.
45
+ * Sanitizes all states if the result is empty.
46
+ */
47
+ DataFlow:: FlowState getAFlowState ( ) { none ( ) }
48
+ }
43
49
44
50
/**
45
51
* DEPRECATED: Use `Sanitizer` instead.
@@ -68,4 +74,24 @@ module CodeInjection {
68
74
else result = FlowState:: full ( ) // If it "just" loads something, then it's only vulnerable if the attacker controls the entire string.
69
75
}
70
76
}
77
+
78
+ private import codeql.ruby.AST as Ast
79
+
80
+ /**
81
+ * A string-concatenation that sanitizes the `full()` state.
82
+ */
83
+ class StringConcatenationSanitizer extends Sanitizer {
84
+ StringConcatenationSanitizer ( ) {
85
+ // string concatenations sanitize the `full` state, as an attacker no longer controls the entire string
86
+ exists ( Ast:: AstNode str |
87
+ str instanceof Ast:: StringLiteral
88
+ or
89
+ str instanceof Ast:: AddExpr
90
+ |
91
+ this .asExpr ( ) .getExpr ( ) = str
92
+ )
93
+ }
94
+
95
+ override DataFlow:: FlowState getAFlowState ( ) { result = FlowState:: full ( ) }
96
+ }
71
97
}
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import codeql.ruby.DataFlow
9
9
import codeql.ruby.TaintTracking
10
10
import CodeInjectionCustomizations:: CodeInjection
11
11
import codeql.ruby.dataflow.BarrierGuards
12
- private import codeql.ruby.AST as Ast
13
12
14
13
/**
15
14
* A taint-tracking configuration for detecting "Code injection" vulnerabilities.
@@ -26,21 +25,15 @@ class Configuration extends TaintTracking::Configuration {
26
25
}
27
26
28
27
override predicate isSanitizer ( DataFlow:: Node node ) {
29
- node instanceof Sanitizer or
30
- node instanceof StringConstCompareBarrier or
28
+ node instanceof Sanitizer and not exists ( node .( Sanitizer ) .getAFlowState ( ) )
29
+ or
30
+ node instanceof StringConstCompareBarrier
31
+ or
31
32
node instanceof StringConstArrayInclusionCallBarrier
32
33
}
33
34
34
35
override predicate isSanitizer ( DataFlow:: Node node , DataFlow:: FlowState state ) {
35
- // string concatenations sanitize the `full` state, as an attacker no longer controls the entire string
36
- exists ( Ast:: AstNode str |
37
- str instanceof Ast:: StringLiteral
38
- or
39
- str instanceof Ast:: AddExpr
40
- |
41
- node .asExpr ( ) .getExpr ( ) = str and
42
- state = FlowState:: full ( )
43
- )
36
+ node .( Sanitizer ) .getAFlowState ( ) = state
44
37
}
45
38
46
39
deprecated override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
You can’t perform that action at this time.
0 commit comments