Chapter 20. Security
Whether you’re dealing with a user sitting at the keyboard typing commands or someone sending information across the network, you need to be careful about the data coming into your programs. The other person may, either maliciously or accidentally, send you data that will do more harm than good. Perl provides a special security-checking mechanism called taint mode, whose purpose is to isolate tainted data so that you won’t use it to do something you didn’t intend to do. For instance, if you mistakenly trust a tainted filename, you might end up appending an entry to your password file when you thought you were appending to a log file. The mechanism of tainting is covered in the next section, Handling Insecure Data.
In multitasking environments, offstage actions by unseen actors can affect the security of your own program. If you presume exclusive ownership of external objects (especially files) as though yours were the only process on the system, you expose yourself to errors substantially subtler than those that come from directly handling data or code of dubious provenance. Perl helps you out a little here by detecting some situations that are beyond your control; but for those that you can control, the key is understanding which approaches are proof against unseen meddlers. The upcoming section Handling Timing Glitches discusses these matters.
If the data you get from a stranger happens to be a bit of source code to execute, you need to be even more careful ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access