Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
freeze String class
Browse files Browse the repository at this point in the history
Signed-off-by: PJ Hyett <pjhyett@gmail.com>
  • Loading branch information
steve authored and pjhyett committed Jan 24, 2009
1 parent cf407ff commit ff79f9e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions security.rb
Expand Up @@ -13,9 +13,6 @@
end
Kernel.freeze

# disable ObjectSpace
Object.send :remove_const, :ObjectSpace

# make sure all string methods which modify self also taint the string
class String
%w(swapcase! strip! squeeze! reverse! downcase! upcase! delete! slice! replace []= <<).each do |method_name|
Expand Down Expand Up @@ -49,6 +46,7 @@ def #{method_name} *a, &b
end



# Bug in ruby doesn't check taint when an array of globs is passed
class << Dir
# we need to track $SAFE level manually because define_method captures the $SAFE level
Expand All @@ -72,8 +70,14 @@ def set_safe_level
end
end

# freeze String so that the taint method can't be redefined
String.freeze

# freeze Dir so that no one can modify the @@safe_level
Dir.freeze

# freeze method classes so someone cant modify them to catch the original methods
[Method, UnboundMethod].each {|klass| klass.freeze }

# disable ObjectSpace so people cant access the original method objects
Object.send :remove_const, :ObjectSpace

0 comments on commit ff79f9e

Please sign in to comment.