Skip to content

Commit 9fff2cf

Browse files
committed
Ruby: Add missing documentation
1 parent 546bfcb commit 9fff2cf

21 files changed

+154
-6
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the `ActionController` library.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.Concepts
37
private import codeql.ruby.controlflow.CfgNodes
@@ -66,10 +70,14 @@ class ActionControllerActionMethod extends Method, HTTP::Server::RequestHandler:
6670
/** Gets a call to render from within this method. */
6771
RenderCall getARenderCall() { result.getParent+() = this }
6872

69-
// TODO: model the implicit render call when a path through the method does
70-
// not end at an explicit render or redirect
71-
/** Gets the controller class containing this method. */
72-
ActionControllerControllerClass getControllerClass() { result = controllerClass }
73+
/**
74+
* Gets the controller class containing this method.
75+
*/
76+
ActionControllerControllerClass getControllerClass() {
77+
// TODO: model the implicit render call when a path through the method does
78+
// not end at an explicit render or redirect
79+
result = controllerClass
80+
}
7381

7482
/**
7583
* Gets a route to this handler, if one exists.
@@ -101,6 +109,9 @@ private class ActionControllerContextCall extends MethodCall {
101109
this.getEnclosingModule() = controllerClass
102110
}
103111

112+
/**
113+
* Gets the controller class containing this method.
114+
*/
104115
ActionControllerControllerClass getControllerClass() { result = controllerClass }
105116
}
106117

ruby/ql/lib/codeql/ruby/frameworks/ActionView.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the `ActionView` library.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.Concepts
37
private import codeql.ruby.controlflow.CfgNodes
@@ -6,6 +10,9 @@ private import codeql.ruby.dataflow.RemoteFlowSources
610
private import codeql.ruby.ast.internal.Module
711
private import ActionController
812

13+
/**
14+
* Holds if this AST node is in a context where `ActionView` methods are available.
15+
*/
916
predicate inActionViewContext(AstNode n) {
1017
// Within a template
1118
n.getLocation().getFile() instanceof ErbFile
@@ -33,6 +40,9 @@ abstract class HtmlEscapeCall extends MethodCall {
3340
HtmlEscapeCall() { this.getMethodName() = ["html_escape", "html_escape_once", "h"] }
3441
}
3542

43+
/**
44+
* A call to a Rails method that escapes HTML.
45+
*/
3646
class RailsHtmlEscaping extends Escaping::Range, DataFlow::CallNode {
3747
RailsHtmlEscaping() { this.asExpr().getExpr() instanceof HtmlEscapeCall }
3848

@@ -55,6 +65,9 @@ private class ActionViewContextCall extends MethodCall {
5565
inActionViewContext(this)
5666
}
5767

68+
/**
69+
* Holds if this call is located inside an ERb template.
70+
*/
5871
predicate isInErbFile() { this.getLocation().getFile() instanceof ErbFile }
5972
}
6073

@@ -132,6 +145,9 @@ private class ActionViewRenderToCall extends ActionViewContextCall, RenderToCall
132145
class LinkToCall extends ActionViewContextCall {
133146
LinkToCall() { this.getMethodName() = "link_to" }
134147

148+
/**
149+
* Gets the path argument to the call.
150+
*/
135151
Expr getPathArgument() {
136152
// When `link_to` is called with a block, it uses the first argument as the
137153
// path, and otherwise the second argument.

ruby/ql/lib/codeql/ruby/frameworks/ActiveRecord.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the `ActiveRecord` library.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.Concepts
37
private import codeql.ruby.controlflow.CfgNodes
@@ -183,6 +187,9 @@ class PotentiallyUnsafeSqlExecutingMethodCall extends ActiveRecordModelClassMeth
183187
)
184188
}
185189

190+
/**
191+
* Gets the SQL fragment argument of this method call.
192+
*/
186193
Expr getSqlFragmentSinkArgument() { result = sqlFragmentExpr }
187194
}
188195

@@ -208,6 +215,9 @@ class ActiveRecordSqlExecutionRange extends SqlExecution::Range {
208215
*/
209216
abstract class ActiveRecordModelInstantiation extends OrmInstantiation::Range,
210217
DataFlow::LocalSourceNode {
218+
/**
219+
* Gets the `ActiveRecordModelClass` that this instance belongs to.
220+
*/
211221
abstract ActiveRecordModelClass getClass();
212222

213223
bindingset[methodName]

ruby/ql/lib/codeql/ruby/frameworks/ActiveStorage.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the `ActiveStorage` library.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.ApiGraphs
37
private import codeql.ruby.Concepts

ruby/ql/lib/codeql/ruby/frameworks/Core.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the Ruby core libraries.
3+
*/
4+
15
private import codeql.ruby.Concepts
26
private import codeql.ruby.DataFlow
37
private import codeql.ruby.dataflow.FlowSummary

ruby/ql/lib/codeql/ruby/frameworks/XmlParsing.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for common XML libraries.
3+
*/
4+
15
private import codeql.ruby.Concepts
26
private import codeql.ruby.AST
37
private import codeql.ruby.DataFlow
@@ -70,11 +74,26 @@ private newtype TFeature =
7074
TNONET() or
7175
TDTDLOAD()
7276

77+
/**
78+
* A representation of XML features that can be enabled or disabled.
79+
* - `TNOENT`: Enables substitution of external entities.
80+
* - `TNONET`: Disables network access.
81+
* - `TDTDLOAD`: Disables loading of DTDs.
82+
*/
7383
class Feature extends TFeature {
84+
/**
85+
* Gets the bitmask value for this feature.
86+
*/
7487
abstract int getValue();
7588

89+
/**
90+
* Gets the string representation of this feature.
91+
*/
7692
string toString() { result = this.getConstantName() }
7793

94+
/**
95+
* Gets the name of this feature.
96+
*/
7897
abstract string getConstantName();
7998
}
8099

ruby/ql/lib/codeql/ruby/frameworks/core/BasicObject.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
/**
2+
* Provides modeling for the `BasicObject` class.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.Concepts
37
private import codeql.ruby.DataFlow
48

9+
/**
10+
* Provides modeling for the `BasicObject` class.
11+
*/
512
module BasicObject {
613
/**
714
* An instance method on `BasicObject`, which is available to all classes.
@@ -10,6 +17,9 @@ module BasicObject {
1017
BasicObjectInstanceMethodCall() { this.getMethodName() = basicObjectInstanceMethodName() }
1118
}
1219

20+
/**
21+
* Gets the name of an instance method on `BasicObject`.
22+
*/
1323
string basicObjectInstanceMethodName() {
1424
result in [
1525
"equal?", "instance_eval", "instance_exec", "method_missing", "singleton_method_added",

ruby/ql/lib/codeql/ruby/frameworks/core/Kernel.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides modeling for the `Kernel` module.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.ApiGraphs
37
private import codeql.ruby.CFG
@@ -6,7 +10,7 @@ private import codeql.ruby.DataFlow
610
private import codeql.ruby.dataflow.FlowSummary
711
private import codeql.ruby.dataflow.internal.DataFlowDispatch
812

9-
/** Modeling for the `Kernel` class. */
13+
/** Provides modeling for the `Kernel` class. */
1014
module Kernel {
1115
/**
1216
* The `Kernel` module is included by the `Object` class, so its methods are available

ruby/ql/lib/codeql/ruby/frameworks/core/Module.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
/**
2+
* Provides modeling for the `Module` class.
3+
*/
4+
15
private import codeql.ruby.AST
26
private import codeql.ruby.Concepts
37
private import codeql.ruby.DataFlow
48

9+
/**
10+
* Provides modeling for the `Module` class.
11+
*/
512
module Module {
613
/**
714
* A call to `Module#module_eval`, which executes its first argument as Ruby code.

ruby/ql/lib/codeql/ruby/frameworks/core/Object.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
/**
2+
* Provides modeling for the `Object` class.
3+
*/
4+
15
private import codeql.ruby.AST
26

7+
/**
8+
* Provides modeling for the `Object` class.
9+
*/
310
module Object {
411
/**
512
* An instance method on `Object`, which is available to all classes except `BasicObject`.
@@ -8,6 +15,9 @@ module Object {
815
ObjectInstanceMethodCall() { this.getMethodName() = objectInstanceMethodName() }
916
}
1017

18+
/**
19+
* Gets the name of an `Object` instance method.
20+
*/
1121
string objectInstanceMethodName() {
1222
result in [
1323
"!~", "<=>", "===", "=~", "callable_methods", "define_singleton_method", "display",

0 commit comments

Comments
 (0)