GeezerVison is showing github.com — Make predicates containing query logic more self-contained · github/codeql@fb841ea
File treeExpand file treeCollapse file tree Open diff view settings lib/codeql/actions/security
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: actions/ql/lib/codeql/actions/security/CodeInjectionQuery.qll +18-12Lines changed: 18 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,23 +93,29 @@ private module CodeInjectionConfig implements DataFlow::ConfigSig { | 93 | 93 | module CodeInjectionFlow = TaintTracking::Global<CodeInjectionConfig>; | 94 | 94 |
| 95 | 95 | /** | 96 | | - * Holds if the flow from `source` to `sink` has critical severity and they are | 97 | | - * linked by `event`. | | 96 | + * Holds if there is a code injection flow from `source` to `sink` with | | 97 | + * critical severity, linked by `event`. | 98 | 98 | */ | 99 | | -pragma[inline] | 100 | | -predicate criticalSeverity(DataFlow::Node source, DataFlow::Node sink, Event event) { | 101 | | - event = getRelevantCriticalEventForSink(sink) and | 102 | | - source.(RemoteFlowSource).getEventName() = event.getName() | | 99 | +predicate criticalSeverityCodeInjection( | | 100 | + CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink, Event event | | 101 | +) { | | 102 | + CodeInjectionFlow::flowPath(source, sink) and | | 103 | + event = getRelevantCriticalEventForSink(sink.getNode()) and | | 104 | + source.getNode().(RemoteFlowSource).getEventName() = event.getName() | 103 | 105 | } | 104 | 106 |
| 105 | | -/** Holds if the flow from `source` to `sink` has medium severity. */ | 106 | | -pragma[inline] | 107 | | -predicate mediumSeverity(DataFlow::Node source, DataFlow::Node sink) { | 108 | | - not criticalSeverity(source, sink, _) and | | 107 | +/** | | 108 | + * Holds if there is a code injection flow from `source` to `sink` with medium severity. | | 109 | + */ | | 110 | +predicate mediumSeverityCodeInjection( | | 111 | + CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink | | 112 | +) { | | 113 | + CodeInjectionFlow::flowPath(source, sink) and | | 114 | + not criticalSeverityCodeInjection(source, sink, _) and | 109 | 115 | // exclude cases where the sink is a JS script and the expression uses toJson | 110 | 116 | not exists(UsesStep script | | 111 | 117 | script.getCallee() = "actions/github-script" and | 112 | | - script.getArgumentExpr("script") = sink.asExpr() and | 113 | | - exists(getAToJsonReferenceExpression(sink.asExpr().(Expression).getExpression(), _)) | | 118 | + script.getArgumentExpr("script") = sink.getNode().asExpr() and | | 119 | + exists(getAToJsonReferenceExpression(sink.getNode().asExpr().(Expression).getExpression(), _)) | 114 | 120 | ) | 115 | 121 | } |
Collapse file Copy file name to clipboardExpand all lines: actions/ql/src/Security/CWE-094/CodeInjectionCritical.ql +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,9 +20,7 @@ import CodeInjectionFlow::PathGraph | 20 | 20 | import codeql.actions.security.ControlChecks | 21 | 21 |
| 22 | 22 | from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink, Event event | 23 | | -where | 24 | | - CodeInjectionFlow::flowPath(source, sink) and | 25 | | - criticalSeverity(source.getNode(), sink.getNode(), event) | | 23 | +where criticalSeverityCodeInjection(source, sink, event) | 26 | 24 | select sink.getNode(), source, sink, | 27 | 25 | "Potential code injection in $@, which may be controlled by an external user ($@).", sink, | 28 | 26 | sink.getNode().asExpr().(Expression).getRawExpression(), event, event.getName() |
Collapse file Copy file name to clipboardExpand all lines: actions/ql/src/Security/CWE-094/CodeInjectionMedium.ql +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,9 +19,7 @@ import codeql.actions.security.CodeInjectionQuery | 19 | 19 | import CodeInjectionFlow::PathGraph | 20 | 20 |
| 21 | 21 | from CodeInjectionFlow::PathNode source, CodeInjectionFlow::PathNode sink | 22 | | -where | 23 | | - CodeInjectionFlow::flowPath(source, sink) and | 24 | | - mediumSeverity(source.getNode(), sink.getNode()) | | 22 | +where mediumSeverityCodeInjection(source, sink) | 25 | 23 | select sink.getNode(), source, sink, | 26 | 24 | "Potential code injection in $@, which may be controlled by an external user.", sink, | 27 | 25 | sink.getNode().asExpr().(Expression).getRawExpression() |
|