2 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 use PublicInbox::Config;
9 my @mods = qw(DBD::SQLite HTTP::Request::Common Plack::Test
10 URI::Escape Plack::Builder);
14 use_ok 'PublicInbox::WWW';
16 F1V5OR6NMF.3M649JTLO9IXD@tux.localdomain/hehe1"'<foo
17 F1V5NB0PTU.3U0DCVGAJ750Z@tux.localdomain"'<>/foo
18 F1V5NB0PTU.3U0DCVGAJ750Z@tux&.ampersand
19 F1V5MIHGCU.2ABINKW6WBE8N@tux.localdomain/raw
20 F1V5LF9D9C.2QT5PGXZQ050E@tux.localdomain/t.atom
21 F1V58X3CMU.2DCCVAKQZGADV@tux.localdomain/../../../../foo
22 F1TVKINT3G.2S6I36MXMHYG6@tux.localdomain" onclick="alert(1)"
24 my @mids = split(/\n/, $msgs);
25 my $ibx = create_inbox 'bad-mids', version => 2, indexlevel => 'basic', sub {
29 $im->add(PublicInbox::Eml->new(<<"")) or BAIL_OUT;
34 Date: Fri, 02 Oct 1993 00:00:0$i +0000
40 my $cfgpfx = "publicinbox.bad-mids";
42 $cfgpfx.address=$ibx->{-primary_address}
43 $cfgpfx.inboxdir=$ibx->{inboxdir}
45 my $config = PublicInbox::Config->new(\$cfg);
46 my $www = PublicInbox::WWW->new($config);
47 test_psgi(sub { $www->call(@_) }, sub {
49 my $res = $cb->(GET('/bad-mids/'));
50 is($res->code, 200, 'got 200 OK listing');
51 my $raw = $res->content;
52 foreach my $mid (@mids) {
53 ok(index($raw, $mid) < 0, "escaped $mid");
56 my (@xmids) = ($raw =~ m!\bhref="([^"]+?)/T/#u"!sg);
57 is(scalar(@xmids), scalar(@mids),
58 'got escaped links to all messages');
60 @xmids = reverse @xmids;
61 my %uxs = ( gt => '>', lt => '<' );
62 foreach my $i (0..$#xmids) {
64 $uri =~ s/&#([0-9]+);/sprintf("%c", $1)/sge;
65 $uri =~ s/&(lt|gt);/$uxs{$1}/sge;
66 $res = $cb->(GET("/bad-mids/$uri/raw"));
67 is($res->code, 200, 'got 200 OK raw message '.$uri);
68 like($res->content, qr/Message-ID: <\Q$mids[$i]\E>/s,
69 'retrieved correct message');