in reply to Back to acceptable untainted characters
Characters aren't dangerous to your Perl program in itself. Passing them along to something else that may interpret them specially is what's dangerous. And knowing how the components you interact with will interpret the characters is the key to security (at least from this class of problems).
For example:
. This isn't safe; we can see this by thinking about how Perl will interpret their input. Well, inside a string, a variable identifier will be interpreted, which might give away secret information (think $unsafe_input="',\$DATABASE_PASSWORD,'"), so the this-is-a-variable characters are unsafe---$@%. Also, escaping from that quoted string would be a real problem (think $unsafe_input="'; system('cat /etc/passwd'); print '"), so single-quotes are dangerous.eval "print OUT '$unsafe_input' or die";
The other option is to disallow them altogether. This is safer, since it's easier to do this correctly, but it can be restrictive. If you're asking a user to enter a passage from a book, it may not be acceptable to disallow quotation marks. If you're asking a user for a password, you shouldn't reject any characters.
The final thing to keep in mind is when you're restricting characters, it's safer to think of all of the characters you know are safe than aren't. That way if you make a mistake, you've erred on the side of caution.
Taint mode is designed to help you do this, but it only works when it knows which input sources are unsafe, which interactions are unsafe, and when you tell it how to make user input safe for use. You should be using taint mode, but only as a tool for catching you when you make a mistake, not as a primary line of defense.
Whenever you're interacting with some system that a user can't normally interact with (a database you're authenticated to, a shell on a public Web server), think hard about what an attacker could to to make a mess of things, and then prevent it. Try a few things, and see how they're handled. Getting a particularly devious friend or co-worker to think of ways to subvert your system can be effective.
A final note is that some modules can provide extra information to taint, such as telling DBI to treat all queries as an interaction that requires taint checking, or telling CGI that its output should be taint checked. I don't recall the names of these modules, but CPAN should be able to find them.
Update: Fixed eval example near top so it's actually insecure.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Back to acceptable untainted characters
by bradcathey (Prior) on Sep 07, 2003 at 17:38 UTC | |
by jeffa (Bishop) on Sep 07, 2003 at 17:51 UTC | |
by jonadab (Parson) on Sep 09, 2003 at 03:08 UTC | |
by genecutl (Beadle) on Sep 08, 2003 at 21:57 UTC | |
by sgifford (Prior) on Sep 08, 2003 at 15:13 UTC | |
|
Re: Re: Back to acceptable untainted characters
by bradcathey (Prior) on Sep 07, 2003 at 12:37 UTC | |
|
Re: Re: Back to acceptable untainted characters
by bunnyman (Hermit) on Sep 08, 2003 at 19:35 UTC |