{
    "content": [
        {
            "type": "text",
            "text": "# perlsec (perldoc)\n\n## NAME\n\nperlsec - Perl security\n\n## DESCRIPTION\n\nPerl 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 scheme\nwith fewer hidden snags. Additionally, because the language has more builtin functionality, it\ncan rely less upon external (and possibly untrustworthy) programs to accomplish its purposes.\n\n## Sections\n\n- **NAME**\n- **DESCRIPTION**\n- **SECURITY VULNERABILITY CONTACT INFORMATION**\n- **SECURITY MECHANISMS AND CONCERNS** (8 subsections)\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "perlsec",
        "section": "",
        "mode": "perldoc",
        "summary": "perlsec - Perl security",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SECURITY VULNERABILITY CONTACT INFORMATION",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "SECURITY MECHANISMS AND CONCERNS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Taint mode",
                        "lines": 115
                    },
                    {
                        "name": "Laundering and Detecting Tainted Data",
                        "lines": 78
                    },
                    {
                        "name": "Cleaning Up Your Path",
                        "lines": 86
                    },
                    {
                        "name": "Shebang Race Condition",
                        "lines": 55
                    },
                    {
                        "name": "Protecting Your Programs",
                        "lines": 27
                    },
                    {
                        "name": "Unicode",
                        "lines": 4
                    },
                    {
                        "name": "Algorithmic Complexity Attacks",
                        "lines": 82
                    },
                    {
                        "name": "Using Sudo",
                        "lines": 16
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "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 scheme\nwith fewer hidden snags. Additionally, because the language has more builtin functionality, it\ncan rely less upon external (and possibly untrustworthy) programs to accomplish 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 by\nthe Perl security team.\n\nSee perlsecpolicy for additional information.\n",
                "subsections": []
            },
            "SECURITY MECHANISMS AND CONCERNS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Taint mode",
                        "content": "Perl automatically enables a set of special security checks, called *taint mode*, when it\ndetects its program running with differing real and effective user or group IDs. The setuid bit\nin Unix permissions is mode 04000, the setgid bit mode 02000; either or both may be set. You can\nalso enable taint mode explicitly by using the -T command line flag. This flag is *strongly*\nsuggested for server programs and any program run on behalf of someone else, such as a CGI\nscript. 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 obvious\nand subtle traps. Some of these checks are reasonably simple, such as verifying that path\ndirectories aren't writable by others; careful programmers have always used checks like these.\nOther checks, however, are best supported by the language itself, and it is these checks\nespecially that contribute to making a set-id Perl program more secure than the corresponding C\nprogram.\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, locale\ninformation (see perllocale), results of certain system calls (\"readdir()\", \"readlink()\", the\nvariable 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\". Tainted\ndata may not be used directly or indirectly in any command that invokes a sub-shell, nor in any\ncommand that modifies files, directories, or processes, with the following exceptions:\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 external\ndata to affect your control flow. Unless you carefully limit what these symbolic values are,\npeople are able to call functions outside your Perl code, such as POSIX::system, in which\ncase 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 value\nof 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 can\nbe 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 \"Insecure\ndependency\" 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 \"Insecure\ndependency\" message, you can use the \"tainted()\" function of the Scalar::Util module, available\nin your nearby CPAN mirror, and included in Perl starting from the release 5.8.0. Or you may be\nable 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 to\ntest every argument for taintedness. Instead, the slightly more efficient and conservative\napproach is used that if any tainted value has been accessed within the same expression, the\nwhole expression is considered tainted.\n\nBut testing for taintedness gets you only so far. Sometimes you have just to clear your data's\ntaintedness. Values may be untainted by using them as keys in a hash; otherwise the only way to\nbypass the tainting mechanism is by referencing subpatterns from a regular expression match.\nPerl presumes that if you reference a substring using $1, $2, etc. in a non-tainting pattern,\nthat you knew what you were doing when you wrote that pattern. That means using a bit of\nthought--don't just blindly untaint anything, or you defeat the entire mechanism. It's better to\nverify that the variable has only good characters (for certain values of \"good\") rather than\nchecking whether it has any bad characters. That's because it's far too easy to miss bad\ncharacters 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 dot,\ndash, or at going to mean something special to the shell. Use of \"/.+/\" would have been insecure\nin theory because it lets everything through, but Perl doesn't check for that. The lesson is\nthat when untainting, you must be exceedingly careful with your patterns. Laundering data using\nregular expression is the *only* mechanism for untainting dirty data, unless you use the\nstrategy 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 matched\nby \"\\w\" are determined by the locale. Perl considers that locale definitions are untrustworthy\nbecause they contain data from outside the program. If you are writing a locale-aware program,\nand want to launder data with a regular expression containing \"\\w\", put \"no locale\" ahead of the\nexpression in the same block. See \"SECURITY\" in perllocale for further discussion and examples.\n\nSwitches On the \"#!\" Line\nWhen you make a script executable, in order to make it usable as a command, the system will pass\nswitches to perl from the script's #! line. Perl checks that any command line switches given to\na setuid (or setgid) script actually match the ones set on the #! line. Some Unix and Unix-like\nenvironments impose a one-switch limit on the #! line, so you may need to use something like\n\"-wU\" instead of \"-w -U\" under such systems. (This issue should arise only in Unix or Unix-like\nenvironments that support #! and setuid or setgid scripts.)\n\nTaint mode and @INC\nWhen the taint mode (\"-T\") is in effect, the environment variables \"PERL5LIB\" and \"PERLLIB\" are\nignored by Perl. You can still adjust @INC from outside the program by using the \"-I\" command\nline option as explained in perlrun. The two environment variables are ignored because they are\nobscured, and a user running a program could be unaware that they are set, whereas the \"-I\"\noption is clearly visible and therefore permitted.\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 included\nin @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. You\nmay be surprised to get this message even if the pathname to your executable is fully qualified.\nThis is *not* generated because you didn't supply a full path to the program; instead, it's\ngenerated because you never set your PATH environment variable, or you didn't set it to\nsomething that was safe. Because Perl can't guarantee that the executable in question isn't\nitself going to turn around and execute some other program that is dependent on your PATH, it\nmakes sure you set the PATH.\n\nThe PATH isn't the only environment variable which can cause problems. Because some shells may\nuse the variables IFS, CDPATH, ENV, and BASHENV, Perl checks that those are either empty or\nuntainted when starting subprocesses. You may wish to add something like this to your setid and\ntaint-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 group!)\nprivileges. Perl doesn't prevent you from opening tainted filenames for reading, so be careful\nwhat you print out. The tainting mechanism is intended to prevent stupid mistakes, not to remove\nthe 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: just\ncreate a child process with reduced privilege who does the dirty work for you. First, fork a\nchild using the special \"open\" syntax that connects the parent and child by a pipe. Now the\nchild resets its ID set and any other per-process attributes, like environment variables,\numasks, current working directories, back to the originals or known safe values. Then the child\nprocess, which no longer has any special permissions, does the \"open\" or other system call.\nFinally, the child passes the data it managed to access back to the parent. Because the file or\npipe was opened in the child while running under less privilege than the parent, it's not apt to\nbe 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 be\nsubjected 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 \"readdir\"\ninstead.\n\nTaint checking is most useful when although you trust yourself not to have written a program to\ngive away the farm, you don't necessarily trust those who end up using it not to try to trick it\ninto doing something bad. This is the kind of security checking that's useful for set-id\nprograms 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 do\nsomething evil. That's the kind of trust needed when someone hands you a program you've never\nseen before and says, \"Here, run this.\" For that kind of safety, you might want to check out the\nSafe module, included standard in the Perl distribution. This module allows the programmer to\nset up special compartments in which all system operations are trapped and namespace access is\ncarefully controlled. Safe should not be considered bullet-proof, though: it will not prevent\nthe foreign code to set up infinite loops, allocate gigabytes of memory, or even abusing perl\nbugs to make the host interpreter crash or behave in unpredictable ways. In any case it's better\navoided completely if you're really concerned about security.\n"
                    },
                    {
                        "name": "Shebang Race Condition",
                        "content": "Beyond the obvious problems that stem from giving special privileges to systems as flexible as\nscripts, on many versions of Unix, set-id scripts are inherently insecure right from the start.\nThe problem is a race condition in the kernel. Between the time the kernel opens the file to see\nwhich interpreter to run and when the (now-set-id) interpreter turns around and reopens the file\nto interpret it, the file in question may have changed, especially if you have symbolic links on\nyour 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, rather\nthan using a pathname subject to meddling, it instead passes */dev/fd/3*. This is a special file\nalready opened on the script, so that there can be no race condition for evil scripts to\nexploit. On these systems, Perl should be compiled with \"-DSETUIDSCRIPTSARESECURENOW\". The\nConfigure program that builds Perl tries to figure this out for itself, so you should never have\nto specify this yourself. Most modern releases of SysVr4 and BSD 4.4 use this approach to avoid\nthe 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-id\nor doesn't run them at all. Either way avoids the exploitability of the race condition, but\ndoesn'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 will\ncomplain loudly that your set-id script is insecure, and won't run it. When Perl complains, you\nneed to remove the set-id bit from the script to eliminate the vulnerability. Refusing to run\nthe script doesn't in itself close the vulnerability; it is just Perl's way of encouraging you\nto 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 that\nplagues 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 it\nsafe 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 source\nis readable by people on the web, though.) So you have to leave the permissions at the socially\nfriendly 0755 level. This lets people on your local system only see your source.\n\nSome people mistakenly regard this as a security problem. If your program does insecure things,\nand relies on people not knowing how to exploit those insecurities, it is not secure. It is\noften possible for someone to determine the insecure things and exploit them without viewing the\nsource. Security through obscurity, the name for hiding your bugs instead of fixing them, is\nlittle security indeed.\n\nYou can try using encryption via source filters (Filter::* from CPAN, or Filter::Util::Call and\nFilter::Simple since Perl 5.8). But crackers might be able to decrypt it. You can try using the\nbyte code compiler and interpreter described below, but crackers might be able to de-compile it.\nYou can try using the native-code compiler described below, but crackers might be able to\ndisassemble it. These pose varying degrees of difficulty to people wanting to get at your code,\nbut none can definitively conceal it (this is true of every language, not just Perl).\n\nIf you're concerned about people profiting from your code, then the bottom line is that nothing\nbut a restrictive license will give you legal security. License your software and pepper it with\nthreatening statements like \"This is unpublished proprietary software of XYZ Corp. Your access\nto it does not give you permission to use it blah blah blah.\" You should see a lawyer to be sure\nyour 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 pitfalls.\nSee perluniintro for an overview and perlunicode for details, and \"Security Implications of\nUnicode\" 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 the\ninput carefully to consume large amounts of either time or space or both. This can lead into the\nso-called *Denial of Service* (DoS) attacks.\n\n*   Hash Algorithm - Hash algorithms like the one used in Perl are well known to be vulnerable\nto collision attacks on their hash function. Such attacks involve constructing a set of keys\nwhich collide into the same bucket producing inefficient behavior. Such attacks often depend\non discovering the seed of the hash function used to map the keys to buckets. That seed is\nthen used to brute-force a key set which can be used to mount a denial of service attack. In\nPerl 5.8.1 changes were introduced to harden Perl to such attacks, and then later in Perl\n5.18.0 these features were enhanced and 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, this\nseed is randomly initialized at process start. This may be overridden by using the\nPERLHASHSEED environment variable, see \"PERLHASHSEED\" in perlrun. This environment\nvariable controls how items are actually stored, not how they are presented via \"keys\",\n\"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 change\nthe iteration order of that hash. This behavior can be overridden by using\n\"hashtraversalmask()\" 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 no\nlonger predictable in Perl 5.18. This has the intention to make it harder to observe a\ncollision. This behavior can be overridden by using the PERLPERTURBKEYS environment\nvariable, 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 that\nthe default perl hash is robust to attack, we have included the hash function Siphash as\na fall-back option. At the time of release of Perl 5.18.0 Siphash is believed to be of\ncryptographic strength. This is not the default as it is much slower than the default\nhash.\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 to 0\nand setting the PERLHASHSEED to a known value. We do not advise those settings for\nproduction 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 changes\nmade to the hash over its lifetime.\n\nAlso note that while the order of the hash elements might be randomized, this\n\"pseudo-ordering\" should not be used for applications like shuffling a list randomly (use\n\"List::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-deterministic\nFinite Automaton), which among other things means that it can rather easily consume large\namounts of both time and space if the regular expression may match in several ways. Careful\ncrafting of the regular expressions can help but quite often there really isn't much one can\ndo (the book \"Mastering Regular Expressions\" is required reading, see perlfaq2). Running out\nof space manifests itself by Perl running out of memory.\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. Starting\nfrom Perl 5.8.0 a different sorting algorithm, mergesort, is used by default. Mergesort\ncannot 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 other\nusers. It sanitises the execution environment to some extent, and will avoid the shebang race\ncondition. If you don't have the safe version of set-id scripts, then \"sudo\" may be a more\nconvenient way of executing a script as another user than writing a C wrapper would 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 \"sudo\",\nand so won't automatically take its own security precautions such as turning on taint mode.\nWhere \"sudo\" configuration dictates exactly which command can be run, the approved command may\ninclude 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, though\nmany of the issues overlap.\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "\"ENVIRONMENT\" in perlrun for its description of cleaning up environment variables.\n",
                "subsections": []
            }
        }
    }
}