Giter Site home page Giter Site logo

safe_ruby's Introduction

Safe Ruby

Safe Ruby provides a way to run untrusted ruby code outside of the current process in a safe environment. Creating this environment is largery based on jruby sandbox, whitelisting the methods one can use on potentially dangerous classes. Constants are also whitelisted, eliminating some core ruby functionality such as spawning another process.

Getting Started

Run gem install safe_ruby in your terminal, then require 'safe_ruby' in your app and you're ready to go.

Examples

Evaluating ruby code

  SafeRuby.eval('[1,2,3].map{ |n| n + 1 }')    #=> [2, 3, 4]
  
  SafeRuby.eval('system("rm *")')              #=> system is unavailable
  
  SafeRuby.eval('Kernel.abort')                #=> undefined method `abort' for Kernel:Module

Default timeout for evaluating is 5 seconds, but this can be specified.

  SafeRuby.eval('loop{}')                      #<ChildProcess::TimeoutError: process still alive after 5 seconds>
  
  SafeRuby.eval('loop{}', timeout: 1)          #<ChildProcess::TimeoutError: process still alive after 1 seconds>

This library was built for a codeacademy-style tutoring app, so checking answers is built into the SafeRuby class

  SafeRuby.check('[1,2,3].map{ |n| n + 1 }', '[2,3,4]')  #=> true

In this example, the second argument(expected answer) can also be untrusted, it will be run safely.

safe_ruby's People

Contributors

dbc-apprentice avatar ukutaht avatar valeth avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

carsonbaker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.