hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

The Sandbox is Loading Gems and Acting Less Freaky #

by why in inspect

I really hoped that 1.8.5 and the sandbox would go hand and glove, but continuing development has caused a split from Ruby 1.8.5. (See the patch.) But, nevermind that, it’ll be okay, considering that the sandbox now loads gems!

 require 'sandbox'

 hpricot_broken = Sandbox.new :init => :all
 hpricot_broken.eval %{
   require 'rubygems'
   require_gem 'hpricot', '=0.4'
   require 'hpricot'
   puts Hpricot("<a class=test>link</a>").search(".test")
 }

 hpricot_fixed = Sandbox.new :init => :all
 hpricot_fixed.eval %{
   require 'rubygems'
   require_gem 'hpricot', '=0.4.47'
   require 'hpricot'
   puts Hpricot("<a class=test>link</a>").search(".test")
 }

Two separate versions of Hpricot, illustrating a broken version and a fixed version, both inside the same Ruby process. This is a new checkpoint for sandbox and I’m calling it 0.1. (Installation instructions.) Available on my development gems or, better yet, as a tarball.

Okay, with matz’ approval, Ruby in CVS has been patched. This means the patch above has been updated or you can just install Ruby 1.8 from CVS.

said on 30 Aug 2006 at 15:47

Interesting… that really is a tiny patch. But why exactly do you need them to be non-static? (Can you extern them as static?)

Sorry… I’m so rusty (and inexperienced) with C that I probably shouldn’t even be asking! Hah.

I guess I should actually go in and upgrade to 1.8.5… and actually play with Snadbox! Freaky freaky… no more? :)

M.T.

said on 30 Aug 2006 at 15:55

I kept looking at my RedHanded feed, hoping it would do something today. Hooray!

I have some ideas for using snaddox later, could be very handy.

said on 30 Aug 2006 at 18:21

Yey! Hopefully I can get the package maintainer for Ruby on ArchLinux to include this patch.

said on 30 Aug 2006 at 18:28

@Matt, static means “scoped to this compilation unit only”. extern static is bound to have confusing semantics (and is illegal I would imagine).

said on 30 Aug 2006 at 20:28

Ah. I come from a primarily PHP background which has thoroughly messed me up… ;) But I’d still like to know why… :/

Oh, yeah… Hey, _Why… Well done! :D

M.T.

said on 30 Aug 2006 at 22:33

Does this work on ruby 1.9 cvs?

said on 30 Aug 2006 at 22:58

neil: No. Just Ruby 1.8 CVS and a patched 1.8.5.

said on 31 Aug 2006 at 03:09

Just a query, will using Sandbox allow one to prevent DOS style attacks that are still possible with a $SAFE=4 thread?

said on 31 Aug 2006 at 09:11

Eventually. But, for now, attacks which use ensure are still deadly.

said on 31 Aug 2006 at 13:30

Despite all my nattering on about continuations, I think perhaps the best solution is to add a Thread#kill! which bypasses ensure.

I’ll see if I can prepare a patch for ruby-core tonight.

said on 31 Aug 2006 at 13:46

MenTaLguY: This is the kind of can-do attitude I need right now. We’ve been killing threads softly for too long. Let’s have it.

said on 31 Aug 2006 at 15:13

Good news, I’ve got a prototype Thread#kill! working.

Once I backport to 1.8, I think the way I’ll do this is to commit the patch and some bits to sandbox SVN , and let you upstream it with matz.

said on 31 Aug 2006 at 16:02

Okay, comitted to SVN . It’s all yours, pal.

said on 31 Aug 2006 at 17:11

Here’s a question—should we be using $SAFE = 4 even for friendly (i.e. Sandbox.new not Sandbox.safe) sandbox evals?

said on 31 Aug 2006 at 17:53

WHOA . That works! (((*LOVE EXUDES*)))

No, let friendly sandboxes do anything. What’s your concern exactly?

said on 31 Aug 2006 at 18:05

Oh, and $SAFE isn’t requisite for the safe sandbox either, since unsafe methods aren’t even exposed. But it will be an option.

said on 31 Aug 2006 at 19:28

Well, I was just wondering since as of that writing, having a timeout forced $SAFE = 4 too, whether the sandbox was friendly or not. Ok.

said on 31 Aug 2006 at 19:42

Okay, I’ve added a :safelevel option to request what $SAFE to use for the eval (if any).

said on 31 Aug 2006 at 20:06

Here’s another issue—sand_table doesn’t appear to build with 1.8.4 anymore, since 1.8.4 doesn’t appear to export a few things like rb_cBinding. Is that fixable/worth fixing?

11 Jul 2010 at 21:23

* do fancy stuff in your comment.

PREVIEW PANE