]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: only emit ASCII chars in attachment filenames
authorEric Wong <e@80x24.org>
Tue, 4 Jun 2019 02:04:28 +0000 (02:04 +0000)
committerEric Wong <e@80x24.org>
Tue, 4 Jun 2019 10:06:18 +0000 (10:06 +0000)
We don't want to emit funky URLs which can be lost in
translation or cause problems with non-Unicode-aware
clients.

Then, don't accept non-ASCII filenames in URLs, since
a manually-generated URL/filename in attachment downloads
could be used for Unicode homographs to confuse folks who
down the attachment.

lib/PublicInbox/Hval.pm
lib/PublicInbox/View.pm
lib/PublicInbox/WWW.pm

index 95a0f7095b59f2a6683b3921f06cfb07b13939f0..2b4439703f59b692e9c6c80a628c809185c103fa 100644 (file)
@@ -13,6 +13,9 @@ our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename src_escape
                to_attr from_attr/;
 my $enc_ascii = find_encoding('us-ascii');
 
+# safe-ish acceptable filename pattern for portability
+our $FN = '[a-zA-Z0-9][a-zA-Z0-9_\-\.]+[a-zA-Z0-9]'; # needs \z anchor
+
 sub new {
        my ($class, $raw, $href) = @_;
 
index 09afdaf1bd15aa728766eb3104ff32d43057567c..83ae99bca822f103c1479a0100f2dd4b93580915 100644 (file)
@@ -528,7 +528,7 @@ sub attach_link ($$$$;$) {
        $desc = $fn unless defined $desc;
        $desc = '' unless defined $desc;
        my $sfn;
-       if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
+       if (defined $fn && $fn =~ /\A$PublicInbox::Hval::FN\z/o) {
                $sfn = $fn;
        } elsif ($ct eq 'text/plain') {
                $sfn = 'a.txt';
index b6f18f8d8140e130afdc637b4af277b10dc446c2..50b6950cf6aca523e6dc8e708cab6bb193f28af8 100644 (file)
@@ -28,7 +28,7 @@ use PublicInbox::UserContent;
 our $INBOX_RE = qr!\A/([\w\-][\w\.\-]*)!;
 our $MID_RE = qr!([^/]+)!;
 our $END_RE = qr!(T/|t/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
-our $ATTACH_RE = qr!(\d[\.\d]*)-([[:alnum:]][\w\.-]+[[:alnum:]])!i;
+our $ATTACH_RE = qr!([0-9][0-9\.]*)-($PublicInbox::Hval::FN)!;
 our $OID_RE = qr![a-f0-9]{7,40}!;
 
 sub new {