tags:

views:

260

answers:

4
perl -T

Do you use it? Does it helps you to find security holes in your Perl scripts?

+12  A: 

More than that :) it stops your security issues before they become one. It is not a security silver bullet of course... we used to use it (a few years back when I was involved in Perl projects) in any script that was exposed externally (i.e. any mod_perl app) and we found it very useful and made it our policy. It does a few checks and it is handy.. (anything makes things automated)

Perl Security - perlsec recommends it strongly too:

This flag [Taint mode] is strongly suggested for server programs and any program run on behalf of someone else, such as a CGI script. Once taint mode is on, it's on for the remainder of your script.

Maxwell Troy Milton King
Taint mode is a developer tool. It doesn't stop or prevent security issues. It shows you where you have problems, but it relies on you to handle them properly.
brian d foy
That's slightly misleading. It's not a 'developer tool'. Any sysadmin can/should enable taint for Apache/mod_perl to increase the security on their web applications for example. It is a run-time 'mode' (somewhat analogous to Java sandbox or Asp.Net medium-trust in that respect) and you can run in tainted mode on production. No, it doesn't magically make the issues disappear and developers need to be mindful of how they write code in-line with tainted mode, like any other language/platform feature.
Maxwell Troy Milton King
It's not misleading at all. Taint checking does not increase your security one bit. I'm not saying not to use it. Just don't think it's going to protect you. It merely shows you where you should consider protection. I've seen plenty of "taint-safe" programs that still had the same old security problems of unvalidated inputs.
brian d foy
+6  A: 

Most definitely!

$ echo '`rm -rf /`' | perl -Te 'eval while <>'
Insecure dependency in eval while running with -T switch at -e line 1, <> line 1.
Greg Bacon
Hah. You're brave if you actually ran that. I've probably spend 3 hours before hitting the enter key to make sure -T was in my perl command.
Maybe he ran it as user nobody
Paul
+4  A: 

I think taint mode would work best when new code is being developed that everyone is familiar with.

If you have someone else's code that is poorly written, and you run it in Taint mode -- perl will die rather than perform what by the tainting rules are 'unsafe' operations.

In taint mode perl some holes are patched but not all. system("$unfiltered_user_input") will die but Perl could still write $unfiltered_user_input data to a file with a fixed name (because printing tainted data is considered 'safe') and then execute that file with system(). But nothing can check everything.

There's a tradeoff there for using it on legacy apps. When Perl finds an unsafe operation on tainted data it will die -- which means someone must go in and decide what it means to untaint the data, what regexp are needed, before the application will be reliable again.

Some people would prefer insecure, reliable, low cost (for now) to -- secure, broken, need to find the developers. Not that thats good in the long run... but it is not unusual.

Paul
That example of running `system()` on a file containing data obtained from a user is a good one.
j_random_hacker
There are also taint warnings (-t). They warn about the same things but they don't stop your program. Start with those for legacy programs.
brian d foy
+2  A: 

The "Secure Programming Techniques" chapter of Mastering Perl is almost completely devoted to taint checking and how you should use it.

brian d foy