http://qs1969.pair.com?node_id=33902

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

I've noticed that File::Find doesn't work under taint checks. Eg :-
#!/usr/bin/perl -wT use strict; use File::Find; $ENV{PATH} = "/bin:/usr/bin"; $ENV{ENV} = ""; # This produces "Insecure dependency in chdir while running with -T # switch" find( sub { print }, "." );
A bit of rooting about in the source code comes up with the problem - File::Find uses Cwd::cwd which produces tainted results. Eg:-
#!/usr/bin/perl -wT use strict; use Cwd; $ENV{PATH} = "/bin:/usr/bin"; $ENV{ENV} = ""; # This produces "Insecure dependency in system while running with -T # switch" system "ls " . cwd();
Now I can see that it might be advantageous for setuid scripts to think that cwd() returns tainted data, but unfortunately this means that is isn't possible to use File::Find with -T set because the call to Cwd is internal to File::Find and can't be monkeyed with.

Any ideas on how to get around this?

PS This may be a un*x only problem I don't know. I tested this with 5.005_03 on linux.

PPS The code for Cwd::cwd() looks like chop(`pwd`) which is rather unpleasant in my opinion because it is calling the shell which starts another process, takes time etc. (Remove the PATH in the Cwd example above and it will fail with can't find pwd!)