On Aug 30, 2006, at 1:24 PM, snacktime wrote: > On 8/30/06, Ken Bloom <kbloom / gmail.com> wrote: >> snacktime <snacktime / gmail.com> wrote: >> > There really isn't anything you can do to make this safe. Even >> $SAFE >> > itself can be set to a different value from the usercode. >> >> No, it can't. At lower levels it throws a SecurityError saying it >> can't downgrade the safe level. At higher levels, it throws a >> SecurityError saying it can't "can't chage global variable value" >> (i.e. the rules of Level 4 inherently prevent you from changing the >> security level.) > > Ya you are correct, it won't let you change the safe level. I wonder > how hard it would be to bypass it though using something like > rubyinline? Easy for $SAFE <= 3: $ cat desafe.rb require 'rubygems' require 'inline' class DeSafe inline do |builder| builder.prefix "RUBY_EXTERN int ruby_safe_level;" builder.c <<-EOC static void reduce() { ruby_safe_level = 0; } EOC end end $SAFE = ARGV.shift.to_i rescue 0 p $SAFE DeSafe.new.reduce p $SAFE $ rm -fr ~/.ruby_inline/; ruby desafe.rb 4 desafe.rb:20:in `write': Insecure operation `write' at level 4 (SecurityError) from desafe.rb:20:in `p' from desafe.rb:20 $ rm -fr ~/.ruby_inline/; ruby desafe.rb 3 3 0 -- Eric Hodel - drbrain / segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com