1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* doc/security.rdoc: [DOC] update symbols section [ci-skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2015-02-04 16:24:16 +00:00
parent 99eaebcea3
commit 229bfa7bb1

View file

@ -66,16 +66,26 @@ method, variable and constant names. The reason for this is that symbols are
simply integers with names attached to them, so they are faster to look up in
hashtables.
Be careful with passing user input to methods such as +send+,
+instance_variable_get+ or +_set+, +const_get+ or +_set+, etc.
as these methods will convert string parameters to immortal symbols internally.
This means that the memory used by the symbols are never freed. This could
Starting in version 2.2, most symbols can be garbage collected; these are
called <i>mortal</i> symbols. Most symbols you create (e.g. by calling
+to_sym+) are mortal.
<i>Immortal</i> symbols on the other hand will never be garbage collected.
They are created when modifying code:
* defining a method (e.g. with +define_method+),
* setting an instance variable (e.g. with +instance_variable_set+),
* creating a variable or constant (e.g. with +const_set+)
Also, C extensions that have not been updated and are still calling `ID2SYM`
will create immortal symbols.
Don't create immortal symbols from user inputs. Otherwise, this would
allow a user to mount a denial of service attack against your application by
flooding it with unique strings, which will cause memory to grow indefinitely
until the Ruby process is killed or causes the system to slow to a halt.
The workaround to this is simple - don't call reflection/metaprogramming
methods with user input.
While it might not be a good idea to call these with user inputs, methods that
used to be vulnerable such as +to_sym+, +send+, +respond_to?+,
+method+, +instance_variable_get+, +const_get+, etc. are no longer a threat.
== Regular expressions