# SAFE levels

**URL:** <https://www.ruby-forum.com/t/safe-levels/66113>\
**Category:** Ruby\
**Created:** [February 12, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/safe-levels/66113 "2006-02-12T14:54:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [February 12, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/safe-levels/66113/1 "2006-02-12T14:54:51Z")

</div>

Is there somewhere I can find some description on the proper care and  
feeding of  
Ruby SafeLevels?

I was going to start looking into Rails, but the notion of SafeLevel = 0  
being a  
requirement is kind of a “really bad idea” (Assumption: this is still  
valid for  
mod\_ruby) in my opinion.

But it can still be useful to work under CGI (again, assuming the  
SafeLevel can  
be \>0) and not worry about doing something fundamentally dumb.

From a Perl background much of this makes wonderful sense until I get  
to the  
SafeLevel of a tainted object. How do you cleans such a beast?  
untainting  
strings is trivial, but larger objects… My Perl background fails me  
at this  
point.

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [February 12, 2006, 9:13pm UTC](https://www.ruby-forum.com/t/safe-levels/66113/2 "2006-02-12T21:13:13Z")

</div>

DÅ?a NedeÄ¾a 12 FebruÃ¡r 2006 14:54 Tom A. napÃ­sal:

> From a Perl background much of this makes wonderful sense until I get to  
> the SafeLevel of a tainted object. How do you cleans such a beast?  
> untainting strings is trivial, but larger objects… My Perl background  
> fails me at this point.

irb(main):001:0\> require ‘ostruct’  
=\> true  
irb(main):002:0\> foo = OpenStruct.new  
=\>   
irb(main):003:0\> foo.tainted?  
=\> false  
irb(main):004:0\> foo.bar = gets  
quux  
=\> “quux\n”  
irb(main):005:0\> foo.bar.tainted?  
=\> true  
irb(main):006:0\> foo.tainted?  
=\> false

irb(main):001:0\> foo = gets  
bar  
=\> “bar\n”  
irb(main):002:0\> “foo = #{foo}”  
=\> “foo = bar\n”  
irb(main):003:0\> \_.tainted?  
=\> true  
irb(main):004:0\> foo = gets  
%s  
=\> “%s\n”  
irb(main):005:0\> foo % “bar”  
=\> “bar\n”  
irb(main):006:0\> \_.tainted?  
=\> true  
irb(main):007:0\>

Whether an object is tainted or not depends on the class of the object.  
By  
default, any objects are untainted unless you decide to taint them. If  
Rails  
provides you with a tainted object, it’s your responsibility to sanitize  
it’s  
attributes, and then call #untaint on it.

There’s usually no magic involved in deciding whether an object is or  
isn’t  
tainted, short of the well known tainting strings from user input, and  
any  
strings resulting from interpolation of these with or into other  
strings.

David V.

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [February 13, 2006, 1:08am UTC](https://www.ruby-forum.com/t/safe-levels/66113/3 "2006-02-13T01:08:35Z")

</div>

What’s that “\_” method/object? Google doesn’t search on punctuation  
apparently :-/

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [February 13, 2006, 1:30am UTC](https://www.ruby-forum.com/t/safe-levels/66113/4 "2006-02-13T01:30:53Z")

</div>

DÅ?a Pondelok 13 FebruÃ¡r 2006 01:08 removed\_email\_address@domain.invalid napÃ­sal:

> What’s that “\_” method/object? Google doesn’t search on punctuation  
> apparently :-/

irb automatically populates the \_ variable with the result of the last  
line  
executed. \_\_ is two lines past, \_\_\_ three lines past. I didn’t feel like  
using half a million metasyntactic identifiers cluttering up the  
session.
