@@ -54,11 +54,11 @@ a class that has a getter method with a custom name.
54
54
<p >
55
55
The example dynamically constructs a string which is then executed using <code >module_eval</code >.
56
56
This code will break if the specified name is not a valid Ruby identifier, and
57
- if the value is controlled by an attacker, then this could lead to code injection.
57
+ if the value is controlled by an attacker, then this could lead to code- injection.
58
58
</p >
59
59
60
60
<p >
61
- A more robust implementation, that is also immune to code injection,
61
+ A more robust implementation, that is also immune to code- injection,
62
62
can be made by using <code >module_eval</code > with a block and using <code >define_method</code >
63
63
to define the getter method.
64
64
</p >
@@ -80,13 +80,14 @@ and methods.
80
80
A safer approach is to use <code >class_variable_set</code > and
81
81
<code >class_variable_get</code > along with <code >define_method</code >. String
82
82
interpolation is still used to construct the class variable name, but this is
83
- safe because <code >class_variable_set</code > is not susceptible to code injection.
84
- To construct a dynamic method call we use <code >send</code >, which is ulnerable
85
- to code injection: if an attacker can control the first argument, they can call
86
- any method on the receiver. However this is less powerful than being able to run
87
- arbitrary Ruby code, so it is an improvement in security. We also document to
88
- callers that they should not pass arbitrary user data to the <code >name</code >
89
- parameter.
83
+ safe because <code >class_variable_set</code > is not susceptible to code-injection.
84
+ </p >
85
+
86
+ <p >
87
+ <code >send</code > is used to dynamically call the method specified by <code >name</code >.
88
+ This is a more robust alternative than the previous example, because it does not allow
89
+ arbitrary code to be executed, but it does still allow for any method to be called
90
+ on the target object.
90
91
</p >
91
92
92
93
<sample src =" examples/UnsafeCodeConstruction3Safe.rb" />
0 commit comments