{
    "mode": "man",
    "parameter": "perlsec",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/perlsec/json",
    "generated": "2026-08-09T22:07:14Z",
    "sections": {
        "NAME": {
            "content": "perlsec - Perl security\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Perl is designed to make it easy to program securely even when running with extra privileges,\nlike setuid or setgid programs.  Unlike most command line shells, which are based on multiple\nsubstitution passes on each line of the script, Perl uses a more conventional evaluation\nscheme with fewer hidden snags.  Additionally, because the language has more builtin\nfunctionality, it can rely less upon external (and possibly untrustworthy) programs to\naccomplish its purposes.\n",
            "subsections": []
        },
        "SECURITY VULNERABILITY CONTACT INFORMATION": {
            "content": "If you believe you have found a security vulnerability in the Perl interpreter or modules\nmaintained in the core Perl codebase, email the details to perl-security@perl.org\n<mailto:perl-security@perl.org>.  This address is a closed membership mailing list monitored\nby the Perl security team.\n\nSee perlsecpolicy for additional information.\n",
            "subsections": []
        },
        "SECURITY MECHANISMS AND CONCERNS": {
            "content": "",
            "subsections": [
                {
                    "name": "Taint mode",
                    "content": "By default, Perl automatically enables a set of special security checks, called taint mode,\nwhen it detects its program running with differing real and effective user or group IDs.  The\nsetuid bit in Unix permissions is mode 04000, the setgid bit mode 02000; either or both may\nbe set.  You can also enable taint mode explicitly by using the -T command line flag.  This\nflag is strongly suggested for server programs and any program run on behalf of someone else,\nsuch as a CGI script.  Once taint mode is on, it's on for the remainder of your script.\n\nWhile in this mode, Perl takes special precautions called taint checks to prevent both\nobvious and subtle traps.  Some of these checks are reasonably simple, such as verifying that\npath directories aren't writable by others; careful programmers have always used checks like\nthese.  Other checks, however, are best supported by the language itself, and it is these\nchecks especially that contribute to making a set-id Perl program more secure than the\ncorresponding C program.\n\nYou may not use data derived from outside your program to affect something else outside your\nprogram--at least, not by accident.  All command line arguments, environment variables,\nlocale information (see perllocale), results of certain system calls (readdir(), readlink(),\nthe variable of shmread(), the messages returned by msgrcv(), the password, gcos and shell\nfields returned by the getpwxxx() calls), and all file input are marked as \"tainted\".\nTainted data may not be used directly or indirectly in any command that invokes a sub-shell,\nnor in any command that modifies files, directories, or processes, with the following\nexceptions:\n\nSupport for taint checks adds an overhead to all Perl programs, whether or not you're using\nthe taint features.  Perl 5.18 introduced C preprocessor symbols that can be used to disable\nthe taint features.\n\n•   Arguments to \"print\" and \"syswrite\" are not checked for taintedness.\n\n•   Symbolic methods\n\n$obj->$method(@args);\n\nand symbolic sub references\n\n&{$foo}(@args);\n$foo->(@args);\n\nare  not  checked  for  taintedness.   This  requires  extra  carefulness unless you want\nexternal data to affect your  control  flow.   Unless  you  carefully  limit  what  these\nsymbolic  values  are,  people are able to call functions outside your Perl code, such as\nPOSIX::system, in which case they are able to run arbitrary external code.\n\n•   Hash keys are never tainted.\n\nFor efficiency reasons, Perl takes a conservative view of whether data  is  tainted.   If  an\nexpression  contains  tainted  data, any subexpression may be considered tainted, even if the\nvalue of the subexpression is not itself affected by the tainted data.\n\nBecause taintedness is associated with each scalar value, some elements of an array  or  hash\ncan be tainted and others not.  The keys of a hash are never tainted.\n\nFor example:\n\n$arg = shift;               # $arg is tainted\n$hid = $arg . 'bar';        # $hid is also tainted\n$line = <>;                 # Tainted\n$line = <STDIN>;            # Also tainted\nopen FOO, \"/home/me/bar\" or die $!;\n$line = <FOO>;              # Still tainted\n$path = $ENV{'PATH'};       # Tainted, but see below\n$data = 'abc';              # Not tainted\n\nsystem \"echo $arg\";         # Insecure\nsystem \"/bin/echo\", $arg;   # Considered insecure\n# (Perl doesn't know about /bin/echo)\nsystem \"echo $hid\";         # Insecure\nsystem \"echo $data\";        # Insecure until PATH set\n\n$path = $ENV{'PATH'};       # $path now tainted\n\n$ENV{'PATH'} = '/bin:/usr/bin';\ndelete @ENV{'IFS', 'CDPATH', 'ENV', 'BASHENV'};\n\n$path = $ENV{'PATH'};       # $path now NOT tainted\nsystem \"echo $data\";        # Is secure now!\n\nopen(FOO, \"< $arg\");        # OK - read-only file\nopen(FOO, \"> $arg\");        # Not OK - trying to write\n\nopen(FOO,\"echo $arg|\");     # Not OK\nopen(FOO,\"-|\")\nor exec 'echo', $arg;   # Also not OK\n\n$shout = `echo $arg`;       # Insecure, $shout now tainted\n\nunlink $data, $arg;         # Insecure\numask $arg;                 # Insecure\n\nexec \"echo $arg\";           # Insecure\nexec \"echo\", $arg;          # Insecure\nexec \"sh\", '-c', $arg;      # Very insecure!\n\n@files = <*.c>;             # insecure (uses readdir() or similar)\n@files = glob('*.c');       # insecure (uses readdir() or similar)\n\n# In either case, the results of glob are tainted, since the list of\n# filenames comes from outside of the program.\n\n$bad = ($arg, 23);          # $bad will be tainted\n$arg, `true`;               # Insecure (although it isn't really)\n\nIf  you  try  to  do  something  insecure,  you  will get a fatal error saying something like\n\"Insecure dependency\" or \"Insecure $ENV{PATH}\".\n\nThe exception to the principle of \"one tainted value taints the whole expression\" is with the\nternary conditional operator \"?:\".  Since code with a ternary conditional\n\n$result = $taintedvalue ? \"Untainted\" : \"Also untainted\";\n\nis effectively\n\nif ( $taintedvalue ) {\n$result = \"Untainted\";\n} else {\n$result = \"Also untainted\";\n}\n\nit doesn't make sense for $result to be tainted.\n"
                },
                {
                    "name": "Laundering and Detecting Tainted Data",
                    "content": "To test whether a variable contains tainted  data,  and  whose  use  would  thus  trigger  an\n\"Insecure dependency\" message, you can use the tainted() function of the Scalar::Util module,\navailable  in  your nearby CPAN mirror, and included in Perl starting from the release 5.8.0.\nOr you may be able to use the following istainted() function.\n\nsub istainted {\nlocal $@;   # Don't pollute caller's value.\nreturn ! eval { eval(\"#\" . substr(join(\"\", @), 0, 0)); 1 };\n}\n\nThis function makes use of the fact that the presence of  tainted  data  anywhere  within  an\nexpression renders the entire expression tainted.  It would be inefficient for every operator\nto   test  every  argument  for  taintedness.   Instead,  the  slightly  more  efficient  and\nconservative approach is used that if any tainted value has been  accessed  within  the  same\nexpression, the whole expression is considered tainted.\n\nBut  testing  for  taintedness  gets  you only so far.  Sometimes you have just to clear your\ndata's taintedness.  Values may be untainted by using them as keys in a hash;  otherwise  the\nonly  way  to  bypass  the  tainting  mechanism  is by referencing subpatterns from a regular\nexpression match.  Perl presumes that if you reference a substring using $1, $2,  etc.  in  a\nnon-tainting  pattern,  that  you knew what you were doing when you wrote that pattern.  That\nmeans using a bit of thought--don't just blindly untaint anything, or you defeat  the  entire\nmechanism.   It's  better  to  verify that the variable has only good characters (for certain\nvalues of \"good\") rather than checking whether it has any  bad  characters.   That's  because\nit's far too easy to miss bad characters that you never thought of.\n\nHere's a test to make sure that the data contains nothing but \"word\" characters (alphabetics,\nnumerics, and underscores), a hyphen, an at sign, or a dot.\n\nif ($data =~ /^([-\\@\\w.]+)$/) {\n$data = $1;                     # $data now untainted\n} else {\ndie \"Bad data in '$data'\";      # log this somewhere\n}\n\nThis  is  fairly  secure because \"/\\w+/\" doesn't normally match shell metacharacters, nor are\ndot, dash, or at going to mean something special to the shell.  Use of \"/.+/\" would have been\ninsecure in theory because it lets everything through, but Perl doesn't check for that.   The\nlesson  is  that  when  untainting,  you  must  be  exceedingly  careful  with your patterns.\nLaundering data using regular expression is the only mechanism  for  untainting  dirty  data,\nunless you use the strategy detailed below to fork a child of lesser privilege.\n\nThe  example  does  not  untaint  $data  if \"use locale\" is in effect, because the characters\nmatched by \"\\w\" are determined by the locale.  Perl considers  that  locale  definitions  are\nuntrustworthy  because  they  contain  data  from  outside the program.  If you are writing a\nlocale-aware program, and want to launder data with a regular expression containing \"\\w\", put\n\"no locale\" ahead of the expression in the same block.   See  \"SECURITY\"  in  perllocale  for\nfurther discussion and examples.\n"
                },
                {
                    "name": "Switches On the \"#!\" Line",
                    "content": "When  you  make a script executable, in order to make it usable as a command, the system will\npass switches to perl from the script's #!  line.  Perl checks that any command line switches\ngiven to a setuid (or setgid) script actually match the ones set on the #! line.   Some  Unix\nand  Unix-like environments impose a one-switch limit on the #!  line, so you may need to use\nsomething like \"-wU\" instead of \"-w -U\" under such systems.  (This issue should arise only in\nUnix or Unix-like environments that support #! and setuid or setgid scripts.)\n"
                },
                {
                    "name": "Taint mode and @INC",
                    "content": "+When the taint mode (\"-T\") is in effect, the environment variables  +\"PERL5LIB\",  \"PERLLIB\",\nand  \"PERLUSEUNSAFEINC\"  are  ignored by Perl.  You can still adjust @INC from outside the\nprogram by using the \"-I\" command line option as explained in perlrun.  The  two  environment\nvariables  are  ignored  because  they  are  obscured,  and a user running a program could be\nunaware that they are  set,  whereas  the  \"-I\"  option  is  clearly  visible  and  therefore\npermitted.\n\nAnother way to modify @INC without modifying the program, is to use the \"lib\" pragma, e.g.:\n\nperl -Mlib=/foo program\n\nThe benefit of using \"-Mlib=/foo\" over \"-I/foo\", is that the former will automagically remove\nany duplicated directories, while the latter will not.\n\nNote that if a tainted string is added to @INC, the following problem will be reported:\n\nInsecure dependency in require while running with -T switch\n\nOn versions of Perl before 5.26, activating taint mode will also remove the current directory\n(\".\")  from  the  default  value  of  @INC.  Since  version 5.26, the current directory isn't\nincluded in @INC by default.\n"
                },
                {
                    "name": "Cleaning Up Your Path",
                    "content": "For \"Insecure $ENV{PATH}\" messages, you need to set $ENV{'PATH'} to a known value,  and  each\ndirectory  in  the path must be absolute and non-writable by others than its owner and group.\nYou may be surprised to get this message even if the pathname to  your  executable  is  fully\nqualified.   This  is  not  generated  because  you didn't supply a full path to the program;\ninstead, it's generated because you never set your PATH environment variable, or  you  didn't\nset  it  to  something  that  was  safe.  Because Perl can't guarantee that the executable in\nquestion isn't itself going to turn around and execute some other program that  is  dependent\non your PATH, it makes sure you set the PATH.\n\nThe  PATH  isn't the only environment variable which can cause problems.  Because some shells\nmay use the variables IFS, CDPATH, ENV, and BASHENV, Perl checks that those are either empty\nor untainted when starting subprocesses.  You may wish to add something  like  this  to  your\nsetid and taint-checking scripts.\n\ndelete @ENV{qw(IFS CDPATH ENV BASHENV)};   # Make %ENV safer\n\nIt's also possible to get into trouble with other operations that don't care whether they use\ntainted  values.   Make  judicious  use  of  the file tests in dealing with any user-supplied\nfilenames.  When possible, do opens and such after properly dropping  any  special  user  (or\ngroup!)  privileges.  Perl doesn't prevent you from opening tainted filenames for reading, so\nbe  careful  what  you  print  out.   The  tainting  mechanism  is intended to prevent stupid\nmistakes, not to remove the need for thought.\n\nPerl does not call the shell to expand wild cards when you pass \"system\" and \"exec\"  explicit\nparameter lists instead of strings with possible shell wildcards in them.  Unfortunately, the\n\"open\",  \"glob\", and backtick functions provide no such alternate calling convention, so more\nsubterfuge will be required.\n\nPerl provides a reasonably safe way to open a file or pipe from a setuid or  setgid  program:\njust  create  a child process with reduced privilege who does the dirty work for you.  First,\nfork a child using the special \"open\" syntax that connects the parent and child  by  a  pipe.\nNow  the  child  resets  its  ID  set  and any other per-process attributes, like environment\nvariables, umasks, current working directories, back to the originals or known  safe  values.\nThen the child process, which no longer has any special permissions, does the \"open\" or other\nsystem  call.   Finally,  the  child passes the data it managed to access back to the parent.\nBecause the file or pipe was opened in the child while running under less privilege than  the\nparent, it's not apt to be tricked into doing something it shouldn't.\n\nHere's  a  way to do backticks reasonably safely.  Notice how the \"exec\" is not called with a\nstring that the shell could expand.  This is by far the best way to call something that might\nbe subjected to shell escapes: just never call the shell at all.\n\nuse English;\ndie \"Can't fork: $!\" unless defined($pid = open(KID, \"-|\"));\nif ($pid) {           # parent\nwhile (<KID>) {\n# do something\n}\nclose KID;\n} else {\nmy @temp     = ($EUID, $EGID);\nmy $origuid = $UID;\nmy $origgid = $GID;\n$EUID = $UID;\n$EGID = $GID;\n# Drop privileges\n$UID  = $origuid;\n$GID  = $origgid;\n# Make sure privs are really gone\n($EUID, $EGID) = @temp;\ndie \"Can't drop privileges\"\nunless $UID == $EUID  && $GID eq $EGID;\n$ENV{PATH} = \"/bin:/usr/bin\"; # Minimal PATH.\n# Consider sanitizing the environment even more.\nexec 'myprog', 'arg1', 'arg2'\nor die \"can't exec myprog: $!\";\n}\n\nA similar strategy would work for  wildcard  expansion  via  \"glob\",  although  you  can  use\n\"readdir\" instead.\n\nTaint  checking is most useful when although you trust yourself not to have written a program\nto give away the farm, you don't necessarily trust those who end up using it not  to  try  to\ntrick  it  into doing something bad.  This is the kind of security checking that's useful for\nset-id programs and programs launched on someone else's behalf, like CGI programs.\n\nThis is quite different, however, from not even trusting the writer of the code not to try to\ndo something evil.  That's the kind of trust needed when someone hands you a  program  you've\nnever  seen  before  and  says, \"Here, run this.\"  For that kind of safety, you might want to\ncheck out the Safe module, included standard in the Perl distribution.   This  module  allows\nthe  programmer to set up special compartments in which all system operations are trapped and\nnamespace access is carefully  controlled.   Safe  should  not  be  considered  bullet-proof,\nthough:  it will not prevent the foreign code to set up infinite loops, allocate gigabytes of\nmemory, or even  abusing  perl  bugs  to  make  the  host  interpreter  crash  or  behave  in\nunpredictable  ways.   In  any case it's better avoided completely if you're really concerned\nabout security.\n"
                },
                {
                    "name": "Shebang Race Condition",
                    "content": "Beyond the obvious problems that stem from giving special privileges to systems  as  flexible\nas  scripts,  on many versions of Unix, set-id scripts are inherently insecure right from the\nstart.  The problem is a race condition in the kernel.  Between the time the kernel opens the\nfile to see which interpreter to run and when the (now-set-id) interpreter turns  around  and\nreopens  the  file  to interpret it, the file in question may have changed, especially if you\nhave symbolic links on your system.\n\nSome Unixes, especially more recent ones, are free of this inherent security  bug.   On  such\nsystems,  when  the  kernel  passes the name of the set-id script to open to the interpreter,\nrather than using a pathname subject to meddling, it instead passes  /dev/fd/3.   This  is  a\nspecial  file  already  opened on the script, so that there can be no race condition for evil\nscripts   to   exploit.    On   these    systems,    Perl    should    be    compiled    with\n\"-DSETUIDSCRIPTSARESECURENOW\".   The  Configure  program that builds Perl tries to figure\nthis out for itself, so you should never have to specify this yourself.  Most modern releases\nof SysVr4 and BSD 4.4 use this approach to avoid the kernel race condition.\n\nIf you don't have the safe version of set-id scripts, all is not lost.  Sometimes this kernel\n\"feature\" can be disabled, so that the kernel either doesn't run set-id scripts with the set-\nid or doesn't run them at all.  Either way avoids the exploitability of the  race  condition,\nbut doesn't help in actually running scripts set-id.\n\nIf  the  kernel  set-id  script  feature  isn't  disabled, then any set-id script provides an\nexploitable vulnerability.  Perl can't avoid being exploitable, but will point out vulnerable\nscripts where it can.  If Perl detects that it is being applied to a set-id  script  then  it\nwill  complain  loudly  that  your  set-id  script  is insecure, and won't run it.  When Perl\ncomplains, you need to remove the set-id bit from the script to eliminate the  vulnerability.\nRefusing  to  run the script doesn't in itself close the vulnerability; it is just Perl's way\nof encouraging you to do this.\n\nTo actually run a script set-id, if you don't have the safe version of set-id scripts, you'll\nneed to put a C wrapper around the script.  A C wrapper is just a compiled program that  does\nnothing  except call your Perl program.   Compiled programs are not subject to the kernel bug\nthat plagues set-id scripts.  Here's a simple wrapper, written in C:\n\n#include <unistd.h>\n#include <stdio.h>\n#include <string.h>\n#include <errno.h>\n\n#define REALPATH \"/path/to/script\"\n\nint main(int argc, char argv)\n{\nexecv(REALPATH, argv);\nfprintf(stderr, \"%s: %s: %s\\n\",\nargv[0], REALPATH, strerror(errno));\nreturn 127;\n}\n\nCompile this wrapper into a binary executable and then make it rather than your script setuid\nor setgid.  Note that this wrapper isn't doing anything to sanitise the execution environment\nother than ensuring that a safe path to the script is used.  It only avoids the shebang  race\ncondition.  It relies on Perl's own features, and on the script itself being careful, to make\nit safe enough to run the script set-id.\n"
                },
                {
                    "name": "Protecting Your Programs",
                    "content": "There  are  a number of ways to hide the source to your Perl programs, with varying levels of\n\"security\".\n\nFirst of all, however, you can't take away read permission, because the source code has to be\nreadable in order to be compiled and interpreted.  (That doesn't mean  that  a  CGI  script's\nsource  is  readable  by people on the web, though.)  So you have to leave the permissions at\nthe socially friendly 0755 level.  This lets people  on  your  local  system  only  see  your\nsource.\n\nSome  people  mistakenly  regard  this  as a security problem.  If your program does insecure\nthings, and relies on people not knowing how to exploit those insecurities, it is not secure.\nIt is often possible for someone to determine the insecure things and  exploit  them  without\nviewing  the  source.   Security  through obscurity, the name for hiding your bugs instead of\nfixing them, is little security indeed.\n\nYou can try using encryption via source filters (Filter::* from CPAN,  or  Filter::Util::Call\nand  Filter::Simple  since Perl 5.8).  But crackers might be able to decrypt it.  You can try\nusing the byte code compiler and interpreter described below, but crackers might be  able  to\nde-compile  it.   You  can  try  using the native-code compiler described below, but crackers\nmight be able to disassemble it.  These pose varying degrees of difficulty to people  wanting\nto  get  at  your code, but none can definitively conceal it (this is true of every language,\nnot just Perl).\n\nIf you're concerned about people profiting from your code,  then  the  bottom  line  is  that\nnothing  but  a  restrictive license will give you legal security.  License your software and\npepper it with threatening statements like \"This is unpublished proprietary software  of  XYZ\nCorp.   Your access to it does not give you permission to use it blah blah blah.\"  You should\nsee a lawyer to be sure your license's wording will stand up in court.\n"
                },
                {
                    "name": "Unicode",
                    "content": "Unicode is a new and  complex  technology  and  one  may  easily  overlook  certain  security\npitfalls.   See  perluniintro  for  an  overview  and  perlunicode for details, and \"Security\nImplications of Unicode\" in perlunicode for security implications in particular.\n"
                },
                {
                    "name": "Algorithmic Complexity Attacks",
                    "content": "Certain internal algorithms used in the implementation of Perl can be  attacked  by  choosing\nthe  input carefully to consume large amounts of either time or space or both.  This can lead\ninto the so-called Denial of Service (DoS) attacks.\n\n•   Hash Algorithm - Hash algorithms like  the  one  used  in  Perl  are  well  known  to  be\nvulnerable   to   collision  attacks  on  their  hash  function.   Such  attacks  involve\nconstructing a set of keys which collide  into  the  same  bucket  producing  inefficient\nbehavior.  Such attacks often depend on discovering the seed of the hash function used to\nmap  the  keys  to buckets.  That seed is then used to brute-force a key set which can be\nused to mount a denial of service attack.  In  Perl  5.8.1  changes  were  introduced  to\nharden  Perl  to such attacks, and then later in Perl 5.18.0 these features were enhanced\nand additional protections added.\n\nAt the time of this writing, Perl  5.18.0  is  considered  to  be  well-hardened  against\nalgorithmic  complexity  attacks on its hash implementation.  This is largely owed to the\nfollowing measures mitigate attacks:\n\nHash Seed Randomization\nIn order to make it impossible to know what seed to generate an attack key  set  for,\nthis  seed is randomly initialized at process start.  This may be overridden by using\nthe PERLHASHSEED environment  variable,  see  \"PERLHASHSEED\"  in  perlrun.   This\nenvironment  variable  controls  how  items  are  actually  stored,  not how they are\npresented via \"keys\", \"values\" and \"each\".\n\nHash Traversal Randomization\nIndependent of which seed is used in the hash function, \"keys\", \"values\", and  \"each\"\nreturn  items  in  a  per-hash  randomized order.  Modifying a hash by insertion will\nchange the iteration order of that hash.  This behavior can be  overridden  by  using\nhashtraversalmask()  from  Hash::Util or by using the PERLPERTURBKEYS environment\nvariable, see \"PERLPERTURBKEYS\" in perlrun.  Note that this  feature  controls  the\n\"visible\" order of the keys, and not the actual order they are stored in.\n\nBucket Order Perturbance\nWhen items collide into a given hash bucket the order they are stored in the chain is\nno  longer  predictable  in  Perl  5.18.  This has the intention to make it harder to\nobserve a collision.  This behavior can be overridden by using the  PERLPERTURBKEYS\nenvironment variable, see \"PERLPERTURBKEYS\" in perlrun.\n\nNew Default Hash Function\nThe default hash function has been modified with the intention of making it harder to\ninfer the hash seed.\n\nAlternative Hash Functions\nThe  source  code includes multiple hash algorithms to choose from.  While we believe\nthat the default perl hash is robust to attack, we have included  the  hash  function\nSiphash  as  a  fall-back  option.   At the time of release of Perl 5.18.0 Siphash is\nbelieved to be of cryptographic strength.  This is not the  default  as  it  is  much\nslower than the default hash.\n\nWithout  compiling  a special Perl, there is no way to get the exact same behavior of any\nversions prior to Perl 5.18.0.  The closest one can get is by  setting  PERLPERTURBKEYS\nto  0  and  setting the PERLHASHSEED to a known value.  We do not advise those settings\nfor production use due to the above security considerations.\n\nPerl has never guaranteed any ordering of the hash keys, and  the  ordering  has  already\nchanged several times during the lifetime of Perl 5.  Also, the ordering of hash keys has\nalways  been,  and  continues  to  be, affected by the insertion order and the history of\nchanges made to the hash over its lifetime.\n\nAlso note that while the order of the hash elements might be  randomized,  this  \"pseudo-\nordering\"  should  not  be  used  for  applications  like  shuffling a list randomly (use\nList::Util::shuffle() for that, see List::Util, a standard core module since Perl  5.8.0;\nor  the CPAN module \"Algorithm::Numerical::Shuffle\"), or for generating permutations (use\ne.g. the CPAN modules  \"Algorithm::Permute\"  or  \"Algorithm::FastPermute\"),  or  for  any\ncryptographic applications.\n\nTied hashes may have their own ordering and algorithmic complexity attacks.\n\n•   Regular   expressions  -  Perl's  regular  expression  engine  is  so  called  NFA  (Non-\ndeterministic Finite Automaton), which among other things means that it can rather easily\nconsume large amounts of both time and space if  the  regular  expression  may  match  in\nseveral ways.  Careful crafting of the regular expressions can help but quite often there\nreally  isn't  much  one  can  do  (the  book \"Mastering Regular Expressions\" is required\nreading, see perlfaq2).  Running out of space manifests itself by  Perl  running  out  of\nmemory.\n\n•   Sorting  -  the  quicksort  algorithm  used in Perls before 5.8.0 to implement the sort()\nfunction was very easy to trick into misbehaving so that  it  consumes  a  lot  of  time.\nStarting  from  Perl  5.8.0 a different sorting algorithm, mergesort, is used by default.\nMergesort cannot misbehave on any input.\n\nSee <https://www.usenix.org/legacy/events/sec03/tech/fullpapers/crosby/crosby.pdf> for  more\ninformation, and any computer science textbook on algorithmic complexity.\n"
                },
                {
                    "name": "Using Sudo",
                    "content": "The  popular  tool  \"sudo\"  provides a controlled way for users to be able to run programs as\nother users.  It sanitises the execution environment to  some  extent,  and  will  avoid  the\nshebang  race  condition.   If you don't have the safe version of set-id scripts, then \"sudo\"\nmay be a more convenient way of executing a script as another user than writing a  C  wrapper\nwould be.\n\nHowever,  \"sudo\"  sets the real user or group ID to that of the target identity, not just the\neffective ID as set-id bits do.  As a result, Perl can't detect  that  it  is  running  under\n\"sudo\", and so won't automatically take its own security precautions such as turning on taint\nmode.   Where  \"sudo\"  configuration  dictates exactly which command can be run, the approved\ncommand may include a \"-T\" option to perl to enable taint mode.\n\nIn general, it is necessary to evaluate the suitability of  a  script  to  run  under  \"sudo\"\nspecifically  with  that  kind of execution environment in mind.  It is neither necessary nor\nsufficient for the same script to be suitable to run in  a  traditional  set-id  arrangement,\nthough many of the issues overlap.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "\"ENVIRONMENT\" in perlrun for its description of cleaning up environment variables.\n\nperl v5.38.2                                 2026-06-12                                   PERLSEC(1)",
            "subsections": []
        }
    },
    "summary": "perlsec - Perl security",
    "flags": [],
    "examples": [],
    "see_also": []
}