public
Description: checking ruby sexp trees [before eval()], raise security error if excluded code pattern spotted
Homepage: http://rufus.rubyforge.org/rufus-treechecker
Clone URL: git://github.com/jmettraux/rufus-treechecker.git
jmettraux (author)
Mon May 11 22:54:46 -0700 2009
commit  c27b5fa7e2bcb81262f619496c84a76660ad7eef
tree    cf248d3d378eb29cffa7af323f8b87f1d48f504b
parent  845820d87f1abf1db3e9a6f791727147c36725b3
name age message
file CHANGELOG.txt Tue Oct 28 20:51:04 -0700 2008 release 1.0.3 [jmettraux]
file CREDITS.txt Thu Aug 28 19:38:38 -0700 2008 added various .txt artefacts [jmettraux]
file LICENSE.txt Thu Aug 28 19:38:38 -0700 2008 added various .txt artefacts [jmettraux]
file README.txt Sun Nov 09 22:13:33 -0800 2008 doc update [jmettraux]
file Rakefile Thu Mar 12 16:59:13 -0700 2009 moved to hanna rdoc template [jmettraux]
directory doc/ Thu Mar 12 16:59:13 -0700 2009 moved to hanna rdoc template [jmettraux]
file jtest.sh Sat Aug 30 04:03:11 -0700 2008 depending on rogue_parser [jmettraux]
directory lib/ Mon May 11 22:54:46 -0700 2009 cosmetic changes [jmettraux]
directory test/ Thu Mar 12 16:59:13 -0700 2009 moved to hanna rdoc template [jmettraux]
README.txt
= 'rufus-treechecker'

== what is it ?

Initialize a Rufus::TreeChecker and pass some ruby code to make sure it's safe before calling eval().


== getting it

    sudo gem install -y rufus-treechecker

or download[http://rubyforge.org/frs/?group_id=4812] it from RubyForge.


== usage

The treechecker uses ruby_parser (http://rubyforge.org/projects/parsetree)
to turn Ruby code into s-expressions, the treechecker then 
checks this sexp tree and raises a Rufus::SecurityError if an excluded pattern 
is spotted.

The excluded patterns are defined at the initialization of the TreeChecker
instance by listing rules.

    require 'rubygems'
    require 'rufus-treechecker'

    tc = Rufus::TreeChecker.new do
      exclude_fvcall :abort
      exclude_fvcall :exit, :exit!
    end
    
    tc.check("1 + 1; abort")               # will raise a SecurityError
    tc.check("puts (1..10).to_a.inspect")  # OK


Nice, but how do I know what to exclude ?

    require 'rubygems'
    require 'rufus-treechecker'

    Rufus::TreeChecker.new.ptree('a = 5 + 6; puts a')

will yield

    "a = 5 + 6; puts a"
     => 
     [:block, 
       [:lasgn, :a, [:call, [:lit, 5], :+, [:array, [:lit, 6]]]], 
       [:fcall, :puts, [:array, [:lvar, :a]]]
     ]


For more documentation, see http://github.com/jmettraux/rufus-treechecker/tree/master/lib/rufus/treechecker.rb


== dependencies

the 'ruby_parser' gem by Ryan Davis.


== mailing list

On the Rufus-Ruby list[http://groups.google.com/group/rufus-ruby] :

    http://groups.google.com/group/rufus-ruby


== issue tracker

    http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse


== source

http://github.com/jmettraux/rufus-treechecker

    git clone git://github.com/jmettraux/rufus-treechecker.git


== author

John Mettraux, jmettraux@gmail.com,
http://jmettraux.wordpress.com


== the rest of Rufus

http://rufus.rubyforge.org


== license

MIT