1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::Config;
8 use PublicInbox::TestCommon;
9 my @mods = qw(DBD::SQLite HTTP::Request::Common Plack::Test
10 URI::Escape Plack::Builder PublicInbox::WWW);
13 use_ok 'PublicInbox::WWW';
14 use_ok 'PublicInbox::V2Writable';
15 my ($inboxdir, $for_destroy) = tmpdir();
16 my $cfgpfx = "publicinbox.bad-mids";
18 inboxdir => $inboxdir,
21 -primary_address => 'test@example.com',
22 indexlevel => 'basic',
24 $ibx = PublicInbox::Inbox->new($ibx);
25 my $im = PublicInbox::V2Writable->new($ibx, 1);
29 F1V5OR6NMF.3M649JTLO9IXD@tux.localdomain/hehe1"'<foo
30 F1V5NB0PTU.3U0DCVGAJ750Z@tux.localdomain"'<>/foo
31 F1V5NB0PTU.3U0DCVGAJ750Z@tux&.ampersand
32 F1V5MIHGCU.2ABINKW6WBE8N@tux.localdomain/raw
33 F1V5LF9D9C.2QT5PGXZQ050E@tux.localdomain/t.atom
34 F1V58X3CMU.2DCCVAKQZGADV@tux.localdomain/../../../../foo
35 F1TVKINT3G.2S6I36MXMHYG6@tux.localdomain" onclick="alert(1)"
37 my @mids = split(/\n/, $msgs);
39 foreach my $mid (@mids) {
45 Date: Fri, 02 Oct 1993 00:00:0$i +0000
48 my $mime = PublicInbox::MIME->new(\$data);
49 ok($im->add($mime), "added $mid");
55 $cfgpfx.address=$ibx->{-primary_address}
56 $cfgpfx.inboxdir=$inboxdir
58 my $config = PublicInbox::Config->new(\$cfg);
59 my $www = PublicInbox::WWW->new($config);
60 test_psgi(sub { $www->call(@_) }, sub {
62 my $res = $cb->(GET('/bad-mids/'));
63 is($res->code, 200, 'got 200 OK listing');
64 my $raw = $res->content;
65 foreach my $mid (@mids) {
66 ok(index($raw, $mid) < 0, "escaped $mid");
69 my (@xmids) = ($raw =~ m!\bhref="([^"]+)/t\.mbox\.gz"!sg);
70 is(scalar(@xmids), scalar(@mids),
71 'got escaped links to all messages');
73 @xmids = reverse @xmids;
74 my %uxs = ( gt => '>', lt => '<' );
75 foreach my $i (0..$#xmids) {
77 $uri =~ s/&#([0-9]+);/sprintf("%c", $1)/sge;
78 $uri =~ s/&(lt|gt);/$uxs{$1}/sge;
79 $res = $cb->(GET("/bad-mids/$uri/raw"));
80 is($res->code, 200, 'got 200 OK raw message '.$uri);
81 like($res->content, qr/Message-ID: <\Q$mids[$i]\E>/s,
82 'retrieved correct message');