1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

Tainted Data

By

In large programs, especially when heavy abstraction is involved, it's sometimes impossible to tell where your data is coming from. Consider the following situation: a server application takes user input from a client and does some processing. It then offloads some of this processing (for example, resizing an image file) to an external program using the backtick operator. The command passed to the operating system is partially comprised of input from the client, which cannot be trusted. A potential security risk arises.

"Tainted" objects are those that have come from some type of user input. Either from a file, the keyboard or the network, unless the object is a literal in the program or created by the program directly, it will be tainted. The tainted flag is always there on your objects, all you have to do is check it before you do anything unsafe. If you've confirmed that the data is indeed safe, you can then untaint the object.

In addition, any object created from or derived from a tainted object will also be marked tainted. So, if you do a = gets.chomp, a will be tainted and if you then do b = a.reverse b will then also be tainted.

  1. About.com
  2. Technology
  3. Ruby
  4. Advanced Ruby
  5. Tainted Data

©2014 About.com. All rights reserved.