AWS-S3
view release on metacpan or search on metacpan
t/aws/s3/request/uri_injection.t view on Meta::CPAN
#!perl
use strict;
use warnings;
# Bucket names, object keys and query values are caller supplied and end up in
# the URL of the requests we send. They must not be able to change the shape of
# that URL: send the (signed) request to another host, turn an upload into a
# different S3 operation, or inject extra query parameters.
package Capturing::UA;
use parent 'LWP::UserAgent';
our @REQUESTS;
sub request {
my ( $self, $req ) = @_;
push @REQUESTS, $req;
return HTTP::Response->new( 200, 'OK', [ ETag => '"abc"' ] );
}
package main;
use Test::More;
use_ok( 'AWS::S3' );
use_ok( 'AWS::S3::Bucket' );
use_ok( 'AWS::S3::File' );
use_ok( 'AWS::S3::Types' );
my $s3 = AWS::S3->new(
access_key_id => 'foo',
secret_access_key => 'bar',
endpoint => 's3.baz.com',
ua => Capturing::UA->new,
);
my $bucket = AWS::S3::Bucket->new( s3 => $s3, name => 'maibucket' );
# no contents passed so nothing is fetched or sent when the object is built
my $file = AWS::S3::File->new(
key => 'k',
bucket => $bucket,
is_encrypted => 0,
size => 1,
);
# every request type that takes a bucket, and any other required arguments
my %request_args = (
CreateBucket => {},
DeleteBucket => {},
DeleteFile => { key => 'k' },
DeleteMulti => { keys => ['k'] },
GetBucketAccessControl => {},
GetBucketLocationConstraint => {},
GetBucketPolicy => {},
GetFileContents => { key => 'k' },
GetFileInfo => { key => 'k' },
GetPreSignedUrl => { key => 'k', expires => 60 },
ListBucket => { max_keys => 1 },
SetBucketAccessControl => { acl_short => 'private' },
SetBucketPolicy => { policy => '{}' },
SetFileContents => { file => $file },
);
my @good_names = (
'maibucket',
'foo',
'my.dotted-bucket.name',
'Legacy_Bucket_Name', # legacy buckets could have upper case/underscores
'0123',
'a' x 255,
);
my @bad_names = (
'evil.com/x', # would send the request to evil.com
'evil.com#',
'evil.com?',
'user@evil.com',
'evil.com:8080',
'a/b',
'a\\b',
'a b',
'a%2Fb',
"a\nb",
"a\n", # trailing newline, \z not $
"a\r\nHost: evil.com",
'',
'.leadingdot',
'-leadinghyphen',
'_leadingunderscore',
"caf\x{e9}",
'a' x 256,
);
( run in 1.093 second using v1.01-cache-2.11-cpan-eb134014566 )