kryberg has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to put my CGI scripts into taint mode to make them more secure.

I've tried #!/usr/bin/perl -T like all the examples I can find show, with and without warnings.

However, I always get the error message Too late for "-T" option at xxxxx.pl line 1 when I test it in UNIX. The script will still work in the browser though.

What does this error message mean? I've done some searching and haven't found anything about it.

Replies are listed 'Best First'.
Re: Taint Mode
by jsprat (Curate) on Sep 24, 2002 at 18:34 UTC
    I'm surprised nobody has pointed you to perldoc perldiag!

    Too late for "-T" option (X) The #! line (or local equivalent) in a Perl script contains +the -T option, but Perl was not invoked with -T in its command line. This is an error because, by the time Perl discovers a -T in a script, it's too late to properly taint everything from the environment. So Perl gives up. If the Perl script is being executed as a command using the #! mechanism (or its local equivalent), this error can usually be f +ixed by editing the #! line so that the -T option is a part of Perl's first argument: e.g. change "perl -n -T" to "perl -T -n". If the Perl script is being executed as "perl scriptname", then +the -T option must appear on the command line: "perl -T scriptname".
      That is exactly what I was looking for! Bookmarked it for future use. Thanks.
Re: Taint Mode
by fruiture (Curate) on Sep 24, 2002 at 17:15 UTC

    Well, you will get this error message if the shebang line is actually no more used as such:

    $ cat example #!/usr/bin/perl -T print "hello\n"; $ chmod u+x example; example hello $ perl example Too late for "-T" option at ol line 1.

    I can only guess what this means: When you start a script with `perl scriptname`, perl starts up and might enable the "taint mode" or not and _then_ takes your script. Because it's clever it examines the input file for a shebang line and tries to get as much as possible out of it, but '-T' can no more be evaluated. If you start your script as `scriptname`, the shebang is _really_ the perl-call and so perl gets all startup-information from that line. In CGI environment the shebang is also the startup-information-source for perl, so it's not "too" late there.

    --
    http://fruiture.de

      In some close reading of the OpenBSD kernel (for example) you'll notice that the shebang line is handled directly by the underlying exec() call. This is partly where the old thing about interpreted scripts under SUID had issues - #1 the OS reads the file, #2 interpretes the shebang, #3 executes the interpretor, #4 the interpretor reads from the already open file and executes. The attack was to replace the OK code with bad code somewhere between step #1 and step #4.

      I think the fix was to prevent the non-SUID user from getting access to the SUID's user's about-to-be-passed filehandles though I don't really recall.

      Wow. I've never posted here before. That was fast. All the replies helped me understand things better. Thanks.
Re: Taint Mode
by fglock (Vicar) on Sep 24, 2002 at 17:10 UTC

    In command mode, call the script with  perl -T xxxxxx.pl

Re: Taint Mode
by zigdon (Deacon) on Sep 24, 2002 at 17:10 UTC
    However, I always get the error message Too late for "-T" option at xxxxx.pl line 1 when I test it in UNIX. The script will still work in the browser though.

    how are you testing in unix? if by the command line, you have to specify the -T on the command line as well:

    > perl -T /path/to/script.pl

    -- Dan

Re: Taint Mode
by Anonymous Monk on Sep 25, 2002 at 00:19 UTC
    I had the same problem a few days back. On NT/W2K, the #!line is ignored. It is one of the quirks of activestate perl (using activeperl 5.6.1 build 631).You can do two things : 1. Change the perl you associate with your *.pl or *.cgi files to include a '-T' command line option 2. Create a new extension 'tcgi' or 'tpl' and associate this with "C:/whereverYourPerlExeIs/perl.exe -T". Use this extension with all your scripts which need taint checking. Hope this helps. --Mahesh
Re: Taint Mode
by robertv (Initiate) on Sep 24, 2002 at 17:59 UTC
    I had the same problem, even in test scripts that didn't have any data passed to it(made me think what the*****, how can it be to late?). Turns out, and sorry I can't remember where I read it, that -T doesn't work on a Windows platform.
    Robert V.

      It's too bad that you can't remember where you read it. Otherwise, we could correct that information. Taint mode does indeed work on the Windows platform. You just have to make sure that the initial mapping actually used to launch perl has the -T (or -t, I suppose) flag.