Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tainting #383

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Revision history for WWW::Mechanize

{{$NEXT}}
[ENHANCEMENTS]
- WWW::Mechanize no longer taints the responses it receives. This also
removes Test::Taint as a prerequisite.

2.19 2024-09-16 15:25:45Z
[DOCUMENTATION]
Expand Down
1 change: 0 additions & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dir = script
[Prereqs / RuntimeRequires]
perl = 5.008
HTML::Form = 6.08
Scalar::Util = 1.14

[Prereqs / TestRequires]
HTTP::Daemon = 6.12
Expand Down
40 changes: 0 additions & 40 deletions lib/WWW/Mechanize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ use Tie::RefHash ();
use HTTP::Request 1.30 ();
use HTML::Form 1.00 ();
use HTML::TokeParser ();
use Scalar::Util qw( tainted );

use parent 'LWP::UserAgent';

Expand Down Expand Up @@ -3364,8 +3363,6 @@ sub _update_page {
my $content = $res->decoded_content();
$content = $res->content if ( not defined $content );

$content .= _taintedness();

if ( $self->is_html ) {
$self->update_html($content);
}
Expand All @@ -3376,43 +3373,6 @@ sub _update_page {
return $res;
} # _update_page

our $_taintbrush;

# This is lifted wholesale from Test::Taint
sub _taintedness {
return $_taintbrush if defined $_taintbrush;

# Somehow we need to get some taintedness into our $_taintbrush.
# Let's try the easy way first. Either of these should be
# tainted, unless somebody has untainted them, so this
# will almost always work on the first try.
# (Unless, of course, taint checking has been turned off!)
$_taintbrush = substr( "$0$^X", 0, 0 );
return $_taintbrush if tainted($_taintbrush);

# Let's try again. Maybe somebody cleaned those.
$_taintbrush = substr( join( q{}, grep { defined } @ARGV, %ENV ), 0, 0 );
return $_taintbrush if tainted($_taintbrush);

# If those don't work, go try to open some file from some unsafe
# source and get data from them. That data is tainted.
# (Yes, even reading from /dev/null works!)
for my $filename ( qw(/dev/null / . ..), values %INC, $0, $^X ) {
if ( open my $fh, '<', $filename ) {
my $data;
if ( defined sysread $fh, $data, 1 ) {
$_taintbrush = substr( $data, 0, 0 );
last if tainted($_taintbrush);
}
}
}

# Sanity check
die("Our taintbrush should have zero length!") if length $_taintbrush;

return $_taintbrush;
}

=head2 $mech->_modify_request( $req )

Modifies a L<HTTP::Request> before the request is sent out,
Expand Down
2 changes: 1 addition & 1 deletion lib/WWW/Mechanize/Examples.pod
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ WWW::Mechanize.

=back

#!/usr/bin/perl -w -T
#!/usr/bin/perl -w

use strict;
use WWW::Mechanize;
Expand Down
2 changes: 1 addition & 1 deletion t/00-load.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/add_header.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/aliases.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/area_link.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl
# WWW::Mechanize tests for <area> tags

use warnings;
Expand Down
2 changes: 1 addition & 1 deletion t/autocheck.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/clone.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/credentials.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/die.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/field.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_frame.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_image.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_inputs.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_link.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_link_id.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/find_link_xhtml.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/form-parsing.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion t/form_with_fields.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/form_with_fields_passthrough_params.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/frames.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/image-new.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/image-parse.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/link-base.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/link-relative.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/link.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/mech-dump/mech-dump.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/new.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/regex-error.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/save_content.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/select.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
23 changes: 0 additions & 23 deletions t/taint.t

This file was deleted.

2 changes: 1 addition & 1 deletion t/tick.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/upload.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion t/warn.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion t/warnings.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down
2 changes: 1 addition & 1 deletion xt/author/live/wikipedia.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -T
#!perl

use warnings;
use strict;
Expand Down