|
| 1 | +/** |
| 2 | + * Modeling for `railties`, which is a gem containing various internals and utilities for the Rails framework. |
| 3 | + * https://rubygems.org/gems/railties |
| 4 | + */ |
| 5 | + |
| 6 | +private import ruby |
| 7 | +private import codeql.ruby.Concepts |
| 8 | +private import codeql.ruby.ApiGraphs |
| 9 | +private import codeql.ruby.DataFlow |
| 10 | +private import codeql.ruby.ast.internal.Module |
| 11 | + |
| 12 | +/** |
| 13 | + * Modeling for `railties`. |
| 14 | + */ |
| 15 | +module Railties { |
| 16 | + /** |
| 17 | + * A class which `include`s `Rails::Generators::Actions`. |
| 18 | + */ |
| 19 | + private class GeneratorsActionsContext extends ClassDeclaration { |
| 20 | + GeneratorsActionsContext() { |
| 21 | + exists(IncludeOrPrependCall i | |
| 22 | + i.getEnclosingModule() = this and |
| 23 | + i.getArgument(0) = |
| 24 | + API::getTopLevelMember("Rails") |
| 25 | + .getMember("Generators") |
| 26 | + .getMember("Actions") |
| 27 | + .getAUse() |
| 28 | + .asExpr() |
| 29 | + .getExpr() |
| 30 | + ) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * A call to `Rails::Generators::Actions#execute_command`. |
| 36 | + * This method concatenates its first and second arguments and executes the result as a shell command. |
| 37 | + */ |
| 38 | + private class ExecuteCommandCall extends SystemCommandExecution::Range, DataFlow::CallNode { |
| 39 | + ExecuteCommandCall() { |
| 40 | + this.asExpr().getExpr().getEnclosingModule() instanceof GeneratorsActionsContext and |
| 41 | + this.getMethodName() = "execute_command" |
| 42 | + } |
| 43 | + |
| 44 | + override DataFlow::Node getAnArgument() { result = this.getArgument([0, 1]) } |
| 45 | + |
| 46 | + override predicate isShellInterpreted(DataFlow::Node arg) { any() } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * A call to a method in `Rails::Generators::Actions` which delegates to `execute_command`. |
| 51 | + */ |
| 52 | + private class ExecuteCommandWrapperCall extends SystemCommandExecution::Range, DataFlow::CallNode { |
| 53 | + ExecuteCommandWrapperCall() { |
| 54 | + this.asExpr().getExpr().getEnclosingModule() instanceof GeneratorsActionsContext and |
| 55 | + this.getMethodName() = ["rake", "rails_command", "git"] |
| 56 | + } |
| 57 | + |
| 58 | + override DataFlow::Node getAnArgument() { result = this.getArgument(0) } |
| 59 | + |
| 60 | + override predicate isShellInterpreted(DataFlow::Node arg) { any() } |
| 61 | + } |
| 62 | +} |
0 commit comments