mirror of
https://github.com/github/codeql.git
synced 2026-05-22 07:07:09 +02:00
Ruby: add stacktrace exposure query
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Provides default sources, sinks and sanitizers for detecting stack trace
|
||||
* exposure vulnerabilities, as well as extension points for adding your own.
|
||||
*/
|
||||
|
||||
private import codeql.ruby.AST
|
||||
private import codeql.ruby.Concepts
|
||||
private import codeql.ruby.DataFlow
|
||||
private import codeql.ruby.controlflow.CfgNodes
|
||||
private import codeql.ruby.frameworks.core.Kernel
|
||||
|
||||
/**
|
||||
* Provides default sources, sinks and sanitizers for detecting stack trace
|
||||
* exposure vulnerabilities, as well as extension points for adding your own.
|
||||
*/
|
||||
module StackTraceExposure {
|
||||
/** A data flow source for stack trace exposure vulnerabilities. */
|
||||
abstract class Source extends DataFlow::Node { }
|
||||
|
||||
/** A data flow sink for stack trace exposure vulnerabilities. */
|
||||
abstract class Sink extends DataFlow::Node { }
|
||||
|
||||
/** A data flow sanitizer for stack trace exposure vulnerabilities. */
|
||||
abstract class Sanitizer extends DataFlow::Node { }
|
||||
|
||||
/**
|
||||
* A call to `backtrace` or `backtrace_locations` on a `rescue` variable,
|
||||
* considered as a flow source.
|
||||
*/
|
||||
class BacktraceCall extends Source, DataFlow::CallNode {
|
||||
BacktraceCall() {
|
||||
exists(DataFlow::LocalSourceNode varAccess |
|
||||
varAccess.asExpr().(ExprNodes::VariableReadAccessCfgNode).getExpr().getVariable() =
|
||||
any(RescueClause rc).getVariableExpr().(VariableAccess).getVariable() and
|
||||
varAccess.flowsTo(this.getReceiver())
|
||||
) and
|
||||
this.getMethodName() = ["backtrace", "backtrace_locations"]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to `Kernel#caller`, considered as a flow source.
|
||||
*/
|
||||
class KernelCallerCall extends Source, Kernel::KernelMethodCall {
|
||||
KernelCallerCall() { this.getMethodName() = "caller" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The body of an HTTP response that will be returned from a server,
|
||||
* considered as a flow sink.
|
||||
*/
|
||||
class ServerHttpResponseBodyAsSink extends Sink {
|
||||
ServerHttpResponseBodyAsSink() { this = any(Http::Server::HttpResponse response).getBody() }
|
||||
}
|
||||
}
|
||||
25
ruby/ql/lib/codeql/ruby/security/StackTraceExposureQuery.qll
Normal file
25
ruby/ql/lib/codeql/ruby/security/StackTraceExposureQuery.qll
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Provides a taint-tracking configuration for detecting stack-trace exposure
|
||||
* vulnerabilities.
|
||||
*
|
||||
* Note, for performance reasons: only import this file if
|
||||
* `StackTraceExposure::Configuration` is needed; otherwise,
|
||||
* `StackTraceExposureCustomizations` should be imported instead.
|
||||
*/
|
||||
|
||||
private import codeql.ruby.DataFlow
|
||||
private import codeql.ruby.TaintTracking
|
||||
private import StackTraceExposureCustomizations::StackTraceExposure
|
||||
|
||||
/**
|
||||
* A taint-tracking configuration for detecting "stack trace exposure" vulnerabilities.
|
||||
*/
|
||||
class Configuration extends TaintTracking::Configuration {
|
||||
Configuration() { this = "StackTraceExposure" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) { source instanceof Source }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
|
||||
|
||||
override predicate isSanitizer(DataFlow::Node node) { node instanceof Sanitizer }
|
||||
}
|
||||
Reference in New Issue
Block a user