1PERLSEC(1)             Perl Programmers Reference Guide             PERLSEC(1)
2
3
4

NAME

6       perlsec - Perl security
7

DESCRIPTION

9       Perl is designed to make it easy to program securely even when running
10       with extra privileges, like setuid or setgid programs.  Unlike most
11       command line shells, which are based on multiple substitution passes on
12       each line of the script, Perl uses a more conventional evaluation
13       scheme with fewer hidden snags.  Additionally, because the language has
14       more builtin functionality, it can rely less upon external (and
15       possibly untrustworthy) programs to accomplish its purposes.
16

SECURITY VULNERABILITY CONTACT INFORMATION

18       If you believe you have found a security vulnerability in the Perl
19       interpreter or modules maintained in the core Perl codebase, email the
20       details to perl-security@perl.org <mailto:perl-security@perl.org>.
21       This address is a closed membership mailing list monitored by the Perl
22       security team.
23
24       See perlsecpolicy for additional information.
25

SECURITY MECHANISMS AND CONCERNS

27   Taint mode
28       By default, Perl automatically enables a set of special security
29       checks, called taint mode, when it detects its program running with
30       differing real and effective user or group IDs.  The setuid bit in Unix
31       permissions is mode 04000, the setgid bit mode 02000; either or both
32       may be set.  You can also enable taint mode explicitly by using the -T
33       command line flag.  This flag is strongly suggested for server programs
34       and any program run on behalf of someone else, such as a CGI script.
35       Once taint mode is on, it's on for the remainder of your script.
36
37       While in this mode, Perl takes special precautions called taint checks
38       to prevent both obvious and subtle traps.  Some of these checks are
39       reasonably simple, such as verifying that path directories aren't
40       writable by others; careful programmers have always used checks like
41       these.  Other checks, however, are best supported by the language
42       itself, and it is these checks especially that contribute to making a
43       set-id Perl program more secure than the corresponding C program.
44
45       You may not use data derived from outside your program to affect
46       something else outside your program--at least, not by accident.  All
47       command line arguments, environment variables, locale information (see
48       perllocale), results of certain system calls (readdir(), readlink(),
49       the variable of shmread(), the messages returned by msgrcv(), the
50       password, gcos and shell fields returned by the getpwxxx() calls), and
51       all file input are marked as "tainted".  Tainted data may not be used
52       directly or indirectly in any command that invokes a sub-shell, nor in
53       any command that modifies files, directories, or processes, with the
54       following exceptions:
55
56       Support for taint checks adds an overhead to all Perl programs, whether
57       or not you're using the taint features.  Perl 5.18 introduced C
58       preprocessor symbols that can be used to disable the taint features.
59
60       •   Arguments to "print" and "syswrite" are not checked for
61           taintedness.
62
63       •   Symbolic methods
64
65               $obj->$method(@args);
66
67           and symbolic sub references
68
69               &{$foo}(@args);
70               $foo->(@args);
71
72           are not checked for taintedness.  This requires extra carefulness
73           unless you want external data to affect your control flow.  Unless
74           you carefully limit what these symbolic values are, people are able
75           to call functions outside your Perl code, such as POSIX::system, in
76           which case they are able to run arbitrary external code.
77
78       •   Hash keys are never tainted.
79
80       For efficiency reasons, Perl takes a conservative view of whether data
81       is tainted.  If an expression contains tainted data, any subexpression
82       may be considered tainted, even if the value of the subexpression is
83       not itself affected by the tainted data.
84
85       Because taintedness is associated with each scalar value, some elements
86       of an array or hash can be tainted and others not.  The keys of a hash
87       are never tainted.
88
89       For example:
90
91           $arg = shift;               # $arg is tainted
92           $hid = $arg . 'bar';        # $hid is also tainted
93           $line = <>;                 # Tainted
94           $line = <STDIN>;            # Also tainted
95           open FOO, "/home/me/bar" or die $!;
96           $line = <FOO>;              # Still tainted
97           $path = $ENV{'PATH'};       # Tainted, but see below
98           $data = 'abc';              # Not tainted
99
100           system "echo $arg";         # Insecure
101           system "/bin/echo", $arg;   # Considered insecure
102                                       # (Perl doesn't know about /bin/echo)
103           system "echo $hid";         # Insecure
104           system "echo $data";        # Insecure until PATH set
105
106           $path = $ENV{'PATH'};       # $path now tainted
107
108           $ENV{'PATH'} = '/bin:/usr/bin';
109           delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
110
111           $path = $ENV{'PATH'};       # $path now NOT tainted
112           system "echo $data";        # Is secure now!
113
114           open(FOO, "< $arg");        # OK - read-only file
115           open(FOO, "> $arg");        # Not OK - trying to write
116
117           open(FOO,"echo $arg|");     # Not OK
118           open(FOO,"-|")
119               or exec 'echo', $arg;   # Also not OK
120
121           $shout = `echo $arg`;       # Insecure, $shout now tainted
122
123           unlink $data, $arg;         # Insecure
124           umask $arg;                 # Insecure
125
126           exec "echo $arg";           # Insecure
127           exec "echo", $arg;          # Insecure
128           exec "sh", '-c', $arg;      # Very insecure!
129
130           @files = <*.c>;             # insecure (uses readdir() or similar)
131           @files = glob('*.c');       # insecure (uses readdir() or similar)
132
133           # In either case, the results of glob are tainted, since the list of
134           # filenames comes from outside of the program.
135
136           $bad = ($arg, 23);          # $bad will be tainted
137           $arg, `true`;               # Insecure (although it isn't really)
138
139       If you try to do something insecure, you will get a fatal error saying
140       something like "Insecure dependency" or "Insecure $ENV{PATH}".
141
142       The exception to the principle of "one tainted value taints the whole
143       expression" is with the ternary conditional operator "?:".  Since code
144       with a ternary conditional
145
146           $result = $tainted_value ? "Untainted" : "Also untainted";
147
148       is effectively
149
150           if ( $tainted_value ) {
151               $result = "Untainted";
152           } else {
153               $result = "Also untainted";
154           }
155
156       it doesn't make sense for $result to be tainted.
157
158   Laundering and Detecting Tainted Data
159       To test whether a variable contains tainted data, and whose use would
160       thus trigger an "Insecure dependency" message, you can use the
161       tainted() function of the Scalar::Util module, available in your nearby
162       CPAN mirror, and included in Perl starting from the release 5.8.0.  Or
163       you may be able to use the following is_tainted() function.
164
165           sub is_tainted {
166               local $@;   # Don't pollute caller's value.
167               return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
168           }
169
170       This function makes use of the fact that the presence of tainted data
171       anywhere within an expression renders the entire expression tainted.
172       It would be inefficient for every operator to test every argument for
173       taintedness.  Instead, the slightly more efficient and conservative
174       approach is used that if any tainted value has been accessed within the
175       same expression, the whole expression is considered tainted.
176
177       But testing for taintedness gets you only so far.  Sometimes you have
178       just to clear your data's taintedness.  Values may be untainted by
179       using them as keys in a hash; otherwise the only way to bypass the
180       tainting mechanism is by referencing subpatterns from a regular
181       expression match.  Perl presumes that if you reference a substring
182       using $1, $2, etc. in a non-tainting pattern, that you knew what you
183       were doing when you wrote that pattern.  That means using a bit of
184       thought--don't just blindly untaint anything, or you defeat the entire
185       mechanism.  It's better to verify that the variable has only good
186       characters (for certain values of "good") rather than checking whether
187       it has any bad characters.  That's because it's far too easy to miss
188       bad characters that you never thought of.
189
190       Here's a test to make sure that the data contains nothing but "word"
191       characters (alphabetics, numerics, and underscores), a hyphen, an at
192       sign, or a dot.
193
194           if ($data =~ /^([-\@\w.]+)$/) {
195               $data = $1;                     # $data now untainted
196           } else {
197               die "Bad data in '$data'";      # log this somewhere
198           }
199
200       This is fairly secure because "/\w+/" doesn't normally match shell
201       metacharacters, nor are dot, dash, or at going to mean something
202       special to the shell.  Use of "/.+/" would have been insecure in theory
203       because it lets everything through, but Perl doesn't check for that.
204       The lesson is that when untainting, you must be exceedingly careful
205       with your patterns.  Laundering data using regular expression is the
206       only mechanism for untainting dirty data, unless you use the strategy
207       detailed below to fork a child of lesser privilege.
208
209       The example does not untaint $data if "use locale" is in effect,
210       because the characters matched by "\w" are determined by the locale.
211       Perl considers that locale definitions are untrustworthy because they
212       contain data from outside the program.  If you are writing a locale-
213       aware program, and want to launder data with a regular expression
214       containing "\w", put "no locale" ahead of the expression in the same
215       block.  See "SECURITY" in perllocale for further discussion and
216       examples.
217
218   Switches On the "#!" Line
219       When you make a script executable, in order to make it usable as a
220       command, the system will pass switches to perl from the script's #!
221       line.  Perl checks that any command line switches given to a setuid (or
222       setgid) script actually match the ones set on the #! line.  Some Unix
223       and Unix-like environments impose a one-switch limit on the #!  line,
224       so you may need to use something like "-wU" instead of "-w -U" under
225       such systems.  (This issue should arise only in Unix or Unix-like
226       environments that support #! and setuid or setgid scripts.)
227
228   Taint mode and @INC
229       +When the taint mode ("-T") is in effect, the environment variables
230       +"PERL5LIB", "PERLLIB", and "PERL_USE_UNSAFE_INC" are ignored by Perl.
231       You can still adjust @INC from outside the program by using the "-I"
232       command line option as explained in perlrun.  The two environment
233       variables are ignored because they are obscured, and a user running a
234       program could be unaware that they are set, whereas the "-I" option is
235       clearly visible and therefore permitted.
236
237       Another way to modify @INC without modifying the program, is to use the
238       "lib" pragma, e.g.:
239
240         perl -Mlib=/foo program
241
242       The benefit of using "-Mlib=/foo" over "-I/foo", is that the former
243       will automagically remove any duplicated directories, while the latter
244       will not.
245
246       Note that if a tainted string is added to @INC, the following problem
247       will be reported:
248
249         Insecure dependency in require while running with -T switch
250
251       On versions of Perl before 5.26, activating taint mode will also remove
252       the current directory (".") from the default value of @INC. Since
253       version 5.26, the current directory isn't included in @INC by default.
254
255   Cleaning Up Your Path
256       For "Insecure $ENV{PATH}" messages, you need to set $ENV{'PATH'} to a
257       known value, and each directory in the path must be absolute and non-
258       writable by others than its owner and group.  You may be surprised to
259       get this message even if the pathname to your executable is fully
260       qualified.  This is not generated because you didn't supply a full path
261       to the program; instead, it's generated because you never set your PATH
262       environment variable, or you didn't set it to something that was safe.
263       Because Perl can't guarantee that the executable in question isn't
264       itself going to turn around and execute some other program that is
265       dependent on your PATH, it makes sure you set the PATH.
266
267       The PATH isn't the only environment variable which can cause problems.
268       Because some shells may use the variables IFS, CDPATH, ENV, and
269       BASH_ENV, Perl checks that those are either empty or untainted when
270       starting subprocesses.  You may wish to add something like this to your
271       setid and taint-checking scripts.
272
273           delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};   # Make %ENV safer
274
275       It's also possible to get into trouble with other operations that don't
276       care whether they use tainted values.  Make judicious use of the file
277       tests in dealing with any user-supplied filenames.  When possible, do
278       opens and such after properly dropping any special user (or group!)
279       privileges.  Perl doesn't prevent you from opening tainted filenames
280       for reading, so be careful what you print out.  The tainting mechanism
281       is intended to prevent stupid mistakes, not to remove the need for
282       thought.
283
284       Perl does not call the shell to expand wild cards when you pass
285       "system" and "exec" explicit parameter lists instead of strings with
286       possible shell wildcards in them.  Unfortunately, the "open", "glob",
287       and backtick functions provide no such alternate calling convention, so
288       more subterfuge will be required.
289
290       Perl provides a reasonably safe way to open a file or pipe from a
291       setuid or setgid program: just create a child process with reduced
292       privilege who does the dirty work for you.  First, fork a child using
293       the special "open" syntax that connects the parent and child by a pipe.
294       Now the child resets its ID set and any other per-process attributes,
295       like environment variables, umasks, current working directories, back
296       to the originals or known safe values.  Then the child process, which
297       no longer has any special permissions, does the "open" or other system
298       call.  Finally, the child passes the data it managed to access back to
299       the parent.  Because the file or pipe was opened in the child while
300       running under less privilege than the parent, it's not apt to be
301       tricked into doing something it shouldn't.
302
303       Here's a way to do backticks reasonably safely.  Notice how the "exec"
304       is not called with a string that the shell could expand.  This is by
305       far the best way to call something that might be subjected to shell
306       escapes: just never call the shell at all.
307
308               use English;
309               die "Can't fork: $!" unless defined($pid = open(KID, "-|"));
310               if ($pid) {           # parent
311                   while (<KID>) {
312                       # do something
313                   }
314                   close KID;
315               } else {
316                   my @temp     = ($EUID, $EGID);
317                   my $orig_uid = $UID;
318                   my $orig_gid = $GID;
319                   $EUID = $UID;
320                   $EGID = $GID;
321                   # Drop privileges
322                   $UID  = $orig_uid;
323                   $GID  = $orig_gid;
324                   # Make sure privs are really gone
325                   ($EUID, $EGID) = @temp;
326                   die "Can't drop privileges"
327                       unless $UID == $EUID  && $GID eq $EGID;
328                   $ENV{PATH} = "/bin:/usr/bin"; # Minimal PATH.
329                   # Consider sanitizing the environment even more.
330                   exec 'myprog', 'arg1', 'arg2'
331                       or die "can't exec myprog: $!";
332               }
333
334       A similar strategy would work for wildcard expansion via "glob",
335       although you can use "readdir" instead.
336
337       Taint checking is most useful when although you trust yourself not to
338       have written a program to give away the farm, you don't necessarily
339       trust those who end up using it not to try to trick it into doing
340       something bad.  This is the kind of security checking that's useful for
341       set-id programs and programs launched on someone else's behalf, like
342       CGI programs.
343
344       This is quite different, however, from not even trusting the writer of
345       the code not to try to do something evil.  That's the kind of trust
346       needed when someone hands you a program you've never seen before and
347       says, "Here, run this."  For that kind of safety, you might want to
348       check out the Safe module, included standard in the Perl distribution.
349       This module allows the programmer to set up special compartments in
350       which all system operations are trapped and namespace access is
351       carefully controlled.  Safe should not be considered bullet-proof,
352       though: it will not prevent the foreign code to set up infinite loops,
353       allocate gigabytes of memory, or even abusing perl bugs to make the
354       host interpreter crash or behave in unpredictable ways.  In any case
355       it's better avoided completely if you're really concerned about
356       security.
357
358   Shebang Race Condition
359       Beyond the obvious problems that stem from giving special privileges to
360       systems as flexible as scripts, on many versions of Unix, set-id
361       scripts are inherently insecure right from the start.  The problem is a
362       race condition in the kernel.  Between the time the kernel opens the
363       file to see which interpreter to run and when the (now-set-id)
364       interpreter turns around and reopens the file to interpret it, the file
365       in question may have changed, especially if you have symbolic links on
366       your system.
367
368       Some Unixes, especially more recent ones, are free of this inherent
369       security bug.  On such systems, when the kernel passes the name of the
370       set-id script to open to the interpreter, rather than using a pathname
371       subject to meddling, it instead passes /dev/fd/3.  This is a special
372       file already opened on the script, so that there can be no race
373       condition for evil scripts to exploit.  On these systems, Perl should
374       be compiled with "-DSETUID_SCRIPTS_ARE_SECURE_NOW".  The Configure
375       program that builds Perl tries to figure this out for itself, so you
376       should never have to specify this yourself.  Most modern releases of
377       SysVr4 and BSD 4.4 use this approach to avoid the kernel race
378       condition.
379
380       If you don't have the safe version of set-id scripts, all is not lost.
381       Sometimes this kernel "feature" can be disabled, so that the kernel
382       either doesn't run set-id scripts with the set-id or doesn't run them
383       at all.  Either way avoids the exploitability of the race condition,
384       but doesn't help in actually running scripts set-id.
385
386       If the kernel set-id script feature isn't disabled, then any set-id
387       script provides an exploitable vulnerability.  Perl can't avoid being
388       exploitable, but will point out vulnerable scripts where it can.  If
389       Perl detects that it is being applied to a set-id script then it will
390       complain loudly that your set-id script is insecure, and won't run it.
391       When Perl complains, you need to remove the set-id bit from the script
392       to eliminate the vulnerability.  Refusing to run the script doesn't in
393       itself close the vulnerability; it is just Perl's way of encouraging
394       you to do this.
395
396       To actually run a script set-id, if you don't have the safe version of
397       set-id scripts, you'll need to put a C wrapper around the script.  A C
398       wrapper is just a compiled program that does nothing except call your
399       Perl program.   Compiled programs are not subject to the kernel bug
400       that plagues set-id scripts.  Here's a simple wrapper, written in C:
401
402           #include <unistd.h>
403           #include <stdio.h>
404           #include <string.h>
405           #include <errno.h>
406
407           #define REAL_PATH "/path/to/script"
408
409           int main(int argc, char **argv)
410           {
411               execv(REAL_PATH, argv);
412               fprintf(stderr, "%s: %s: %s\n",
413                               argv[0], REAL_PATH, strerror(errno));
414               return 127;
415           }
416
417       Compile this wrapper into a binary executable and then make it rather
418       than your script setuid or setgid.  Note that this wrapper isn't doing
419       anything to sanitise the execution environment other than ensuring that
420       a safe path to the script is used.  It only avoids the shebang race
421       condition.  It relies on Perl's own features, and on the script itself
422       being careful, to make it safe enough to run the script set-id.
423
424   Protecting Your Programs
425       There are a number of ways to hide the source to your Perl programs,
426       with varying levels of "security".
427
428       First of all, however, you can't take away read permission, because the
429       source code has to be readable in order to be compiled and interpreted.
430       (That doesn't mean that a CGI script's source is readable by people on
431       the web, though.)  So you have to leave the permissions at the socially
432       friendly 0755 level.  This lets people on your local system only see
433       your source.
434
435       Some people mistakenly regard this as a security problem.  If your
436       program does insecure things, and relies on people not knowing how to
437       exploit those insecurities, it is not secure.  It is often possible for
438       someone to determine the insecure things and exploit them without
439       viewing the source.  Security through obscurity, the name for hiding
440       your bugs instead of fixing them, is little security indeed.
441
442       You can try using encryption via source filters (Filter::* from CPAN,
443       or Filter::Util::Call and Filter::Simple since Perl 5.8).  But crackers
444       might be able to decrypt it.  You can try using the byte code compiler
445       and interpreter described below, but crackers might be able to de-
446       compile it.  You can try using the native-code compiler described
447       below, but crackers might be able to disassemble it.  These pose
448       varying degrees of difficulty to people wanting to get at your code,
449       but none can definitively conceal it (this is true of every language,
450       not just Perl).
451
452       If you're concerned about people profiting from your code, then the
453       bottom line is that nothing but a restrictive license will give you
454       legal security.  License your software and pepper it with threatening
455       statements like "This is unpublished proprietary software of XYZ Corp.
456       Your access to it does not give you permission to use it blah blah
457       blah."  You should see a lawyer to be sure your license's wording will
458       stand up in court.
459
460   Unicode
461       Unicode is a new and complex technology and one may easily overlook
462       certain security pitfalls.  See perluniintro for an overview and
463       perlunicode for details, and "Security Implications of Unicode" in
464       perlunicode for security implications in particular.
465
466   Algorithmic Complexity Attacks
467       Certain internal algorithms used in the implementation of Perl can be
468       attacked by choosing the input carefully to consume large amounts of
469       either time or space or both.  This can lead into the so-called Denial
470       of Service (DoS) attacks.
471
472       •   Hash Algorithm - Hash algorithms like the one used in Perl are well
473           known to be vulnerable to collision attacks on their hash function.
474           Such attacks involve constructing a set of keys which collide into
475           the same bucket producing inefficient behavior.  Such attacks often
476           depend on discovering the seed of the hash function used to map the
477           keys to buckets.  That seed is then used to brute-force a key set
478           which can be used to mount a denial of service attack.  In Perl
479           5.8.1 changes were introduced to harden Perl to such attacks, and
480           then later in Perl 5.18.0 these features were enhanced and
481           additional protections added.
482
483           At the time of this writing, Perl 5.18.0 is considered to be well-
484           hardened against algorithmic complexity attacks on its hash
485           implementation.  This is largely owed to the following measures
486           mitigate attacks:
487
488           Hash Seed Randomization
489               In order to make it impossible to know what seed to generate an
490               attack key set for, this seed is randomly initialized at
491               process start.  This may be overridden by using the
492               PERL_HASH_SEED environment variable, see "PERL_HASH_SEED" in
493               perlrun.  This environment variable controls how items are
494               actually stored, not how they are presented via "keys",
495               "values" and "each".
496
497           Hash Traversal Randomization
498               Independent of which seed is used in the hash function, "keys",
499               "values", and "each" return items in a per-hash randomized
500               order.  Modifying a hash by insertion will change the iteration
501               order of that hash.  This behavior can be overridden by using
502               hash_traversal_mask() from Hash::Util or by using the
503               PERL_PERTURB_KEYS environment variable, see "PERL_PERTURB_KEYS"
504               in perlrun.  Note that this feature controls the "visible"
505               order of the keys, and not the actual order they are stored in.
506
507           Bucket Order Perturbance
508               When items collide into a given hash bucket the order they are
509               stored in the chain is no longer predictable in Perl 5.18.
510               This has the intention to make it harder to observe a
511               collision.  This behavior can be overridden by using the
512               PERL_PERTURB_KEYS environment variable, see "PERL_PERTURB_KEYS"
513               in perlrun.
514
515           New Default Hash Function
516               The default hash function has been modified with the intention
517               of making it harder to infer the hash seed.
518
519           Alternative Hash Functions
520               The source code includes multiple hash algorithms to choose
521               from.  While we believe that the default perl hash is robust to
522               attack, we have included the hash function Siphash as a fall-
523               back option.  At the time of release of Perl 5.18.0 Siphash is
524               believed to be of cryptographic strength.  This is not the
525               default as it is much slower than the default hash.
526
527           Without compiling a special Perl, there is no way to get the exact
528           same behavior of any versions prior to Perl 5.18.0.  The closest
529           one can get is by setting PERL_PERTURB_KEYS to 0 and setting the
530           PERL_HASH_SEED to a known value.  We do not advise those settings
531           for production use due to the above security considerations.
532
533           Perl has never guaranteed any ordering of the hash keys, and the
534           ordering has already changed several times during the lifetime of
535           Perl 5.  Also, the ordering of hash keys has always been, and
536           continues to be, affected by the insertion order and the history of
537           changes made to the hash over its lifetime.
538
539           Also note that while the order of the hash elements might be
540           randomized, this "pseudo-ordering" should not be used for
541           applications like shuffling a list randomly (use
542           List::Util::shuffle() for that, see List::Util, a standard core
543           module since Perl 5.8.0; or the CPAN module
544           "Algorithm::Numerical::Shuffle"), or for generating permutations
545           (use e.g. the CPAN modules "Algorithm::Permute" or
546           "Algorithm::FastPermute"), or for any cryptographic applications.
547
548           Tied hashes may have their own ordering and algorithmic complexity
549           attacks.
550
551       •   Regular expressions - Perl's regular expression engine is so called
552           NFA (Non-deterministic Finite Automaton), which among other things
553           means that it can rather easily consume large amounts of both time
554           and space if the regular expression may match in several ways.
555           Careful crafting of the regular expressions can help but quite
556           often there really isn't much one can do (the book "Mastering
557           Regular Expressions" is required reading, see perlfaq2).  Running
558           out of space manifests itself by Perl running out of memory.
559
560       •   Sorting - the quicksort algorithm used in Perls before 5.8.0 to
561           implement the sort() function was very easy to trick into
562           misbehaving so that it consumes a lot of time.  Starting from Perl
563           5.8.0 a different sorting algorithm, mergesort, is used by default.
564           Mergesort cannot misbehave on any input.
565
566       See
567       <https://www.usenix.org/legacy/events/sec03/tech/full_papers/crosby/crosby.pdf>
568       for more information, and any computer science textbook on algorithmic
569       complexity.
570
571   Using Sudo
572       The popular tool "sudo" provides a controlled way for users to be able
573       to run programs as other users.  It sanitises the execution environment
574       to some extent, and will avoid the shebang race condition.  If you
575       don't have the safe version of set-id scripts, then "sudo" may be a
576       more convenient way of executing a script as another user than writing
577       a C wrapper would be.
578
579       However, "sudo" sets the real user or group ID to that of the target
580       identity, not just the effective ID as set-id bits do.  As a result,
581       Perl can't detect that it is running under "sudo", and so won't
582       automatically take its own security precautions such as turning on
583       taint mode.  Where "sudo" configuration dictates exactly which command
584       can be run, the approved command may include a "-T" option to perl to
585       enable taint mode.
586
587       In general, it is necessary to evaluate the suitability of a script to
588       run under "sudo" specifically with that kind of execution environment
589       in mind.  It is neither necessary nor sufficient for the same script to
590       be suitable to run in a traditional set-id arrangement, though many of
591       the issues overlap.
592

SEE ALSO

594       "ENVIRONMENT" in perlrun for its description of cleaning up environment
595       variables.
596
597
598
599perl v5.38.2                      2023-11-30                        PERLSEC(1)
Impressum