| description | Guidance for developing CodeQL queries targeting Ruby code |
|---|
This prompt provides guidance for developing CodeQL queries targeting Ruby code. For common query development patterns and best practices, see query_development.prompt.md.
- Import
rubyfor Ruby AST nodes and predicates - Common imports:
Stmt,Expr,Method,Class,Module,Constant - Use
DataFlowandTaintTrackingfor data flow analysis - Import
codeql.ruby.securityfor security-related predicates
- Toplevel:
Toplevelfor file-level structure - Classes:
ClassDeclarationfor class definitions - Modules:
ModuleDeclarationfor module definitions - Methods:
Method,SingletonMethodfor method definitions - Statements:
StmtSequence,BeginExprfor statement blocks - Expressions:
MethodCall,AssignExpr,IfExpr,CaseExpr,ForExpr,WhileExpr,TernaryIfExpr - Variable Access:
LocalVariableAccess,InstanceVariableAccess,ClassVariableAccess,GlobalVariableAccess - Literals:
StringLiteral,IntegerLiteral,ArrayLiteral,HashLiteral,SymbolLiteral,RegExpLiteral - Control Flow:
WhenClause,RescueClausefor exception handling,Pairfor hash key-value pairs - Blocks:
BraceBlock,DoBlockfor block expressions - Parameters:
SimpleParameter,OptionalParameterfor method parameters
- Metaprogramming:
define_method,method_missing,evalfamily - Reflection:
send,respond_to?,const_get,instance_variable_get - Duck typing: Dynamic method dispatch patterns
- Monkey patching: Class and module reopening
- DSL patterns: Domain-specific language constructs
- Method calls:
call.getMethodName() = "method_name" - Chained calls: Navigate through method chains
- Block usage:
call.getBlock()for blocks passed to methods - Class inheritance:
klass.getSuperClass() - Module inclusion:
include,extend,prependpatterns - Constants:
Constantaccess and scoping - Symbol usage:
:symbolliterals and conversions
- Use
DataFlow::Nodefor nodes in the data flow graph TaintTracking::Configurationfor taint analysis- Handle Ruby's dynamic dispatch and method resolution
- Track through blocks, procs, and lambdas
- Consider instance variables and class variables in flow
- Code injection:
eval,instance_eval,class_evalwith user input - Command injection:
system,exec, backticks with user input - Path traversal: File operations with unsanitized paths
- SQL injection: ActiveRecord and raw SQL with user input
- XSS: HTML output without proper escaping
- YAML/XML deserialization: Unsafe deserialization of user data
- Open redirects: Redirect operations with user-controlled URLs
- Mass assignment: Unsafe parameter handling in frameworks
- Controllers:
ActionController::Basesubclasses - Models:
ActiveRecord::Basesubclasses - Views: ERB templates, helper methods
- Routes: Rails routing patterns
- Callbacks:
before_action,after_action, model callbacks - Strong parameters:
params.require().permit()patterns - Authentication: Devise, session handling
- Authorization: CanCan, Pundit patterns
- File operations:
File,Dir,Pathnameclasses - String operations: String interpolation, regex patterns
- Collections:
Array,Hash,Setoperations - Enumerable:
map,select,reducemethods - Net/HTTP: Web request patterns
- JSON/YAML: Parsing and generation
- Threading:
Thread,Mutex, fiber patterns
- qlt query generate new-query - Generate scaffolding for a new CodeQL query with packs and tests
- codeql query format
- codeql query compile
- codeql query run
- codeql test run