11

I'm aware of the possibility to mark untrusted objects as tainted, but what's the underlying purpose and why should I do it?

1
  • You may also want to look at $SAFE Commented Nov 16, 2009 at 1:19

2 Answers 2

7

One tracks taint as a security precaution, in order to ensure that untrusted data isn't mistakenly used for calculations, transactions, or interpreted as code.

Tracking taint via a built-in language feature is more clear and more reliable than tracking via coding conventions or relying on code review.

For example, input from the user can generally be considered 'untrusted' until it has been sanitized properly for insertion into the database. By marking the input as tainted, Ruby ensures satisfactory sanitation takes place and prevents a potential SQL injection attack.

For an example of an "ancient" (2005) coding practice that demonstrates how taint was tracked without such Perl and Ruby modules, read some good old Joel:

http://www.joelonsoftware.com/articles/Wrong.html

6

It used to be a pretty standard practice when writing CGIs in Perl. There is even a FAQ on it. The basic idea was that the run time could guarantee that you did not implicitly trust a tainted value.

2
  • 3
    And, since the question is tagged 'ruby': Ruby copied this feature from Perl.
    – ephemient
    Commented Nov 15, 2009 at 4:30
  • Oops, I forgot to mention that. Thanks ephemient.
    – D.Shawley
    Commented Nov 15, 2009 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.