🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
10 messages
10 total messages Started by Steve Crook Sat, 26 Dec 2009 15:52
Injection-Info questions
#82425
Author: Steve Crook
Date: Sat, 26 Dec 2009 15:52
19 lines
1760 bytes
Hi all,

I'm in the process of modifying Cleanfeed to correctly interpret the
Injection-Info header and have a couple of questions.

According to RFC5536, the posting-host format should be:
posting-host = "posting.example.com:192.0.2.1"
I assume that whitespace around the '=' is optional (INN2.6.0 doesn't
have it)?  Also, is it safe to assume that the delimiter between
hostname and address is always the *left-most* colon?  I'm thinking
specifically of ipv6 addresses with colons in them.

There also appears to be an issue with Google's implementation of the
header as they currently use:
posting-host=192.0.2.1;
No quotes and no hostname.

No problem accommodating these variations, I just want to make sure I
only accommodate the right ones.  :)
Re: Injection-Info questions
#82426
Author: Julien ÉLIE
Date: Sat, 26 Dec 2009 18:15
76 lines
3903 bytes
Hi Steve,

> According to RFC5536, the posting-host format should be:
> posting-host = "posting.example.com:192.0.2.1"
> I assume that whitespace around the '=' is optional (INN2.6.0 doesn't
> have it)?  Also, is it safe to assume that the delimiter between
> hostname and address is always the *left-most* colon?  I'm thinking
> specifically of ipv6 addresses with colons in them.

Hmm...  As we could have a mere IPv6 address in posting-host, it is
not that simple...
I do not know in fact how to parse it properly in all cases...

>From your own articles:
    posting-host="ip6-localhost:::1"

So we cannot assume there will be a dot before the first colon.

What for:
    posting-host="20bd:20bd::1"

Is it the IPv6 address "20bd:20bd::1" or the host name "20bd" associated
with the IPv6 address "20bd::1"?



As for whitespaces around the '=', I only see that note in RFC 5536:

      NOTE: The syntax of <parameter> (Section 5.1 of [RFC2045], as
      amended by [RFC2231]), taken in conjunction with the folding rules
      of [RFC0822] (note: not [RFC2822] or [RFC5322]), effectively
      allows [CFWS] to occur on either side of the "=" inside a
      <parameter>.

It then appears that whitespaces are allowed.
But I wonder why they have been explicitly allowed.  In fact, this note
seems unclear.  Why should RFC 822 be followed here?  Why RFC 5322
does not mention that?



> There also appears to be an issue with Google's implementation of the
> header as they currently use:
> posting-host=192.0.2.1;
> No quotes and no hostname.

A value is defined in Section 5.1 of RFC 2045:

     value := token / quoted-string
     token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
                 or tspecials>
     tspecials :=  "(" / ")" / "<" / ">" / "@" /
                   "," / ";" / ":" / "\" / <">
                   "/" / "[" / "]" / "?" / "="
                   ; Must be in quoted-string,
                   ; to use within parameter values

Therefore, quoting is not needed for an IPv4 address like "192.0.2.1".

Besides, the hostname is not mandatory.

   host-value      =  dot-atom-text / IPv4address / IPv6address /
                      (dot-atom-text ":" ( IPv4address / IPv6address ))

It can be either a host name, or an IPv4 address, or an IPv6 address,
or a host name followed by a colon and an IPv4 or an IPv6 address.


So I believe their implementation is right.
(We would have to check whether quoting is done on IPv6 addresses.)

-- 
Julien ÉLIE

« En vérité, le chemin importe peu, la volonté d'arriver suffit à tout. » 
Re: Injection-Info questions
#82436
Author: D. Stussy
Date: Sun, 27 Dec 2009 07:55
76 lines
4102 bytes
"Julien ÉLIE" <iulius@nom-de-mon-site.com.invalid> wrote in message
news:hh5jsa$3q1$1@news.trigofacile.com...
> > According to RFC5536, the posting-host format should be:
> > posting-host = "posting.example.com:192.0.2.1"
> > I assume that whitespace around the '=' is optional (INN2.6.0 doesn't
> > have it)?  Also, is it safe to assume that the delimiter between
> > hostname and address is always the *left-most* colon?  I'm thinking
> > specifically of ipv6 addresses with colons in them.
>
> Hmm...  As we could have a mere IPv6 address in posting-host, it is
> not that simple...
> I do not know in fact how to parse it properly in all cases...
>
> From your own articles:
>     posting-host="ip6-localhost:::1"
>
> So we cannot assume there will be a dot before the first colon.
>
> What for:
>     posting-host="20bd:20bd::1"
>
> Is it the IPv6 address "20bd:20bd::1" or the host name "20bd" associated
> with the IPv6 address "20bd::1"?
>
>
>
> As for whitespaces around the '=', I only see that note in RFC 5536:
>
>       NOTE: The syntax of <parameter> (Section 5.1 of [RFC2045], as
>       amended by [RFC2231]), taken in conjunction with the folding rules
>       of [RFC0822] (note: not [RFC2822] or [RFC5322]), effectively
>       allows [CFWS] to occur on either side of the "=" inside a
>       <parameter>.
>
> It then appears that whitespaces are allowed.
> But I wonder why they have been explicitly allowed.  In fact, this note
> seems unclear.  Why should RFC 822 be followed here?  Why RFC 5322
> does not mention that?
>
>
>
> > There also appears to be an issue with Google's implementation of the
> > header as they currently use:
> > posting-host=192.0.2.1;
> > No quotes and no hostname.
>
> A value is defined in Section 5.1 of RFC 2045:
>
>      value := token / quoted-string
>      token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
>                  or tspecials>
>      tspecials :=  "(" / ")" / "<" / ">" / "@" /
>                    "," / ";" / ":" / "\" / <">
>                    "/" / "[" / "]" / "?" / "="
>                    ; Must be in quoted-string,
>                    ; to use within parameter values
>
> Therefore, quoting is not needed for an IPv4 address like "192.0.2.1".
>
> Besides, the hostname is not mandatory.
>
>    host-value      =  dot-atom-text / IPv4address / IPv6address /
>                       (dot-atom-text ":" ( IPv4address / IPv6address ))
>
> It can be either a host name, or an IPv4 address, or an IPv6 address,
> or a host name followed by a colon and an IPv4 or an IPv6 address.
>
>
> So I believe their implementation is right.
> (We would have to check whether quoting is done on IPv6 addresses.)

If we're following RFC 2045 syntax, then IPv6 addresses must be quoted
strings as they contain at least two colons (but only one colon need invoke
the requirement).

Re: Injection-Info questions
#82439
Author: Julien ÉLIE
Date: Tue, 29 Dec 2009 14:53
44 lines
2686 bytes
Hi Steve,

> I'm in the process of modifying Cleanfeed to correctly interpret the
> Injection-Info header and have a couple of questions.

It case it could be of help, there are Perl regexp here for RFC 5322:
    http://cpansearch.perl.org/src/RJBS/Email-Address-1.889/lib/Email/Address.pm

As for RFC 2231-parameters, maybe we should have a look at other Perl parsers
for that.



my $text           = qr/[^\x0A\x0D]/;
my $quoted_pair    = qr/\\$text/;
my $ctext          = qr/(?>[^()\\]+)/;
my ($ccontent, $comment) = (q{})x2;
for (1 .. $COMMENT_NEST_LEVEL) {
  $ccontent = qr/$ctext|$quoted_pair|$comment/;
  $comment  = qr/\s*\((?:\s*$ccontent)*\s*\)\s*/;
}
my $cfws           = qr/$comment|\s+/;
...

They could be helpful to skip CFWS and similar stuff in Injection-Info:

   injection-info  =  "Injection-Info:" SP [CFWS] path-identity
                      [CFWS] *( ";" [CFWS] parameter ) [CFWS] CRLF


Maybe Cleanfeed (and postfilter? -- and of course INN, as well as all news
readers and news servers) should be checked to ensure that all header fields
are properly parsed.
For instance the Newsgroups: header field:

   newsgroup-list  =  *WSP newsgroup-name
                      *( [FWS] "," [FWS] newsgroup-name ) *WSP

-- 
Julien ÉLIE

« Les amis de la vérité sont ceux qui la cherchent,
  et non ceux qui se vantent de l'avoir trouvée. » (Condorcet) 
Re: Injection-Info questions
#82531
Author: Julien ÉLIE
Date: Sun, 10 Jan 2010 14:30
31 lines
2175 bytes
Hi Steve,

> I'm in the process of modifying Cleanfeed to correctly interpret the
> Injection-Info header and have a couple of questions.

Last but not least, we should not forget RFC 2231 that is explicitly
mentioned by RFC 5536.

This way, malicious Injection-Info: header fields can be:

Injection-Info: news.trigofacile.com; posting-host*0=amontpellier;
 (test) posting-host*1="-159-1-21-3.w90-57.abo.wanadoo.fr:90.";
 posting-host*2="57.92.3"; logging-data="3905";

with the first value which is unquoted.

Another one for you:

Injection-Info: news.trigofacile.com;
 posting-host*0*=utf-8'fr'amontpellier;
 (test) posting-host*1="-159-1-21-3.w90-57.abo.wanadoo.fr:90.";
 posting-host*2*="57.92.3"; logging-data="3905";


Parsing is fun :)

-- 
Julien ÉLIE

« Rubor, tumor, dolor, calor et functio laesa. » 
Re: Injection-Info questions
#82539
Author: Steve Crook
Date: Mon, 11 Jan 2010 10:52
29 lines
2085 bytes
On Sun, 10 Jan 2010 15:30:55 +0100, Julien ÉLIE wrote in
Message-Id: <hicoat$fun$1@news.trigofacile.com>:

> Injection-Info: news.trigofacile.com; posting-host*0=amontpellier;
>  (test) posting-host*1="-159-1-21-3.w90-57.abo.wanadoo.fr:90.";
>  posting-host*2="57.92.3"; logging-data="3905";
>
> with the first value which is unquoted.
>
> Another one for you:
>
> Injection-Info: news.trigofacile.com;
>  posting-host*0*=utf-8'fr'amontpellier;
>  (test) posting-host*1="-159-1-21-3.w90-57.abo.wanadoo.fr:90.";
>  posting-host*2*="57.92.3"; logging-data="3905";
>
>
> Parsing is fun :)
Hi Julien,
It is indeed.  The complexity of parsing it is reflected in the lack of
sample code available.  At the moment I'm using two functions, one to
strip nested comments and another to unfold the structured fields into
an array.  It appears to handle your evil examples correctly but it's
possible that I'm misinterpreting what is correct handling in some
instances.  :)

Here is my sample code.  If anyone has suggestions for improving it, I'd
be very happy to hear about them.
http://www.mixmin.net/cleanfeed/injectinfo
Re: Injection-Info questions
#82548
Author: D. Stussy
Date: Mon, 11 Jan 2010 21:38
41 lines
2970 bytes
"Steve Crook" <steve@mixmin.net> wrote in message
news:slrnhkm0mt.lhj.steve@news.mixmin.net...
> ...
> Here is my sample code.  If anyone has suggestions for improving it, I'd
> be very happy to hear about them.
> http://www.mixmin.net/cleanfeed/injectinfo

What if a quoted string inside the data is quoted because it contains a
semicolon?  split() won't parse that properly - but will separate the two
quoted-string halves.  One needs to allow for malformed headers as well as
the properly-formed.

unfold():  I also don't like this:
        $body =~ s/^"//;
        $body =~ s/"$//;
Because it doesn't BALANCE opening and closing quotes.  Maybe you want:
        $body =~ s/^".*"$/&/;
I don't recall if perl allows the ampersand to be assigned the matching
value (like in "vi").  If not, maybe this works:
        $body =~ s/^"(.*)"$/%1/;   (or should that be $1?)

        $body =~ s/\\[^\x0D\x0A]//;
If this is to eliminate folding whitespace, don't we need a whitespace
character to follow?  For EOL, we need "$".  Therefore, might this be what
you want?
        $body =~ s/\\[^\x0D\x0A]([ \t]|$)/%1/;

    $struct_head{hostname} = shift @fields;
Is "hostname" the best name for this value?  How about "posting-server" -
as it's the posting server's name (and in contrast to "posting-host" which
is derrived from the data).  You might not be confused, but I'm thinking
about people who may write additional checks for the header.

I don't even follow or understand your comment_regex() function beyond its
purpose to generate a regex used elsewhere, so my silence on it shouldn't
mean that there's nothing wrong.  I merely accept that it achieves your
goal of stripping all CWFS comments up to 5 levels deep.

Note:  You may know your way around perl regex's better than I do.

Re: Injection-Info questions
#82556
Author: Steve Crook
Date: Tue, 12 Jan 2010 10:47
50 lines
3511 bytes
On Mon, 11 Jan 2010 13:38:15 -0800, D. Stussy wrote in
Message-Id: <hig5ra$9lr$1@snarked.org>:

> What if a quoted string inside the data is quoted because it contains a
> semicolon?  split() won't parse that properly - but will separate the two
> quoted-string halves.  One needs to allow for malformed headers as well as
> the properly-formed.
Yes, I hadn't considered the presence of a semi-colon in a
quoted-string.  It's an invalid atom character but for quoted-strings,
any printable ASCII is valid, excluding \ and ".  I'll need to think
about how to handle that one.

In terms of malformed headers, there is plenty of scope for problems.
Clients of older servers are free to insert anything they like into an
Injection-Info header.  I plan to include some syntax checking but
correctly formatted false data is hard to trap.

> unfold():  I also don't like this:
>         $body =~ s/^"//;
>         $body =~ s/"$//;
> Because it doesn't BALANCE opening and closing quotes.  Maybe you want:
>         $body =~ s/^".*"$/&/;
> I don't recall if perl allows the ampersand to be assigned the matching
> value (like in "vi").  If not, maybe this works:
>         $body =~ s/^"(.*)"$/%1/;   (or should that be $1?)
I agree, that is nicer.  I've now made it s/^"(.*)"$/$1/;

>         $body =~ s/\\[^\x0D\x0A]//;
> If this is to eliminate folding whitespace, don't we need a whitespace
> character to follow?  For EOL, we need "$".  Therefore, might this be what
> you want?
>         $body =~ s/\\[^\x0D\x0A]([ \t]|$)/%1/;
The folded whitespace is handled further up with s/\x0D?\x0A\s*//g;. The
regex you're referring to was cleaning up after splitting the header but
I don't think it's actually required at all now.  I'll do some further
tests.


>     $struct_head{hostname} = shift @fields;
> Is "hostname" the best name for this value?  How about "posting-server" -
> as it's the posting server's name (and in contrast to "posting-host" which
> is derrived from the data).  You might not be confused, but I'm thinking
> about people who may write additional checks for the header.
How about 'injection-server'?

> I don't even follow or understand your comment_regex() function beyond its
> purpose to generate a regex used elsewhere, so my silence on it shouldn't
> mean that there's nothing wrong.  I merely accept that it achieves your
> goal of stripping all CWFS comments up to 5 levels deep.
I take no credit for that one, it's taken from a Cpan package.  :)
Re: Injection-Info questions
#82589
Author: Steve Crook
Date: Thu, 14 Jan 2010 20:37
18 lines
1842 bytes
On Tue, 12 Jan 2010 10:47:54 +0000 (UTC), Steve Crook wrote in
Message-Id: <slrnhkokqq.mgt.steve@news.mixmin.net>:

> Yes, I hadn't considered the presence of a semi-colon in a
> quoted-string.  It's an invalid atom character but for quoted-strings,
> any printable ASCII is valid, excluding \ and ".  I'll need to think
> about how to handle that one.

After much cogitating, I've decided this is a nightmare to handle with a
regex.  Quote chars can be in Comments, Comment chars in Quotes and '='
and semi-colons in both of them.  It's easier to parse it on a
char-by-char basis and then validate the resulting strings against atom,
dot-atom and quoted-text regexs.

Here's a first stab at it:
http://www.mixmin.net/cleanfeed/injectinfo
I can still find ways to break this with malformed data but it's much
easier to fix than the equivalent monster regexs I've tried.
Re: Injection-Info questions
#82592
Author: D. Stussy
Date: Fri, 15 Jan 2010 09:14
92 lines
5409 bytes
"Steve Crook" <steve@mixmin.net> wrote in message
news:slrnhkv04b.mgt.steve@news.mixmin.net...
> On Tue, 12 Jan 2010 10:47:54 +0000 (UTC), Steve Crook wrote in
> Message-Id: <slrnhkokqq.mgt.steve@news.mixmin.net>:
>
> > Yes, I hadn't considered the presence of a semi-colon in a
> > quoted-string.  It's an invalid atom character but for quoted-strings,
> > any printable ASCII is valid, excluding \ and ".  I'll need to think
> > about how to handle that one.
>
> After much cogitating, I've decided this is a nightmare to handle with a
> regex.  Quote chars can be in Comments, Comment chars in Quotes and '='
> and semi-colons in both of them.  It's easier to parse it on a
> char-by-char basis and then validate the resulting strings against atom,
> dot-atom and quoted-text regexs.
>
> Here's a first stab at it:
> http://www.mixmin.net/cleanfeed/injectinfo
> I can still find ways to break this with malformed data but it's much
> easier to fix than the equivalent monster regexs I've tried.

That is a mess.  I'm almost sorry I brought the problem up, but I bet that
someone would probably intrroduce it and it's better to head it off before
it happens.  Looks as if you dealt with it well, but there's still a few
issues:

1) Comments regarding "nested bracket":  A bracket is "[" and "]".
Parentheses are "(" and ")".

-    # Decrement the nested bracket count every time we hit a close bracket
+    # Decrement the nested comment count every time we hit a right
parenthesis.
-    if ($char eq ")" and not $quote_flag) {
+     if ($char eq ")" and not $quote_flag and $comment_level) {
        $comment_level -= 1;
        next;
    };

You don't want to lower the count if we find ")" BEFORE "(" i.e.
$comment_level should never go negative.  ")" is a regular character if NOT
in a comment.


2)
            (my $head, my $body) = split(/=/, $string, 2);
through to
        } else {

I think this assumes that there will be an "=" in the string.  If the
equals-sign is missing, $body should be unset, and although I think your
conditionals do implicitly check for this, we should make certain in
testing.  Is it unset, or is it a null string ("").  It looks as if both
regexes require at least one character, so my concern is does comparing an
unset to a regex throw an exception when "strict" is in force?  If $string
is null, meaning perhaps ";;" (e.g.) appeared in the data, we don't have a
$head either, so we should probably go to the next character.  $string is
already empty but $quoted_string needs to be reset (if we had ';"";').

3) What should we do if either $quote_flag or $comment_level is not zero
when we hit the end of the string?  Does the syntax error mean we should
throw all the results away - or should we try to process what we have, even
if it may be wrong?

4) Lastly, does the "Injection-Info:" header permit omitting the semicolon
at the end of the string?  If so, we could miss the last parameter.
Likewise, if there are NO semi-colons, does this mean we have the injection
server name only?

RFC 5536, Section 3.2.8. (page 20) - Injection-Info:

   injection-info  =  "Injection-Info:" SP [CFWS] path-identity
                      [CFWS] *( ";" [CFWS] parameter ) [CFWS] CRLF

PERMITS - no semicolon -> "path-identity" (injecting server name) only.
NO TRAILING semicolon.  It separates the optional parameters.  It does NOT
terminate them.

Therefore, everything inside "    if ($char eq ";" and not $quote_flag) {"
needs to be repeated after the end of the data in @chars EXCEPT for the
last two lines that merely reset for the next parsing loop -- OR [easier -
hint] we could cheat by appending a semicolon to the string end before
entering the foreach loop (like in your sample testing string - although a
trailing null parameter is technically illegal).

+ $injection_info =~ s/$/\;/;
  foreach my $char (@chars) {

I wasn't certain if the semicolon inside the expression needed to be
backspace-escaped, so I did so anyway.  Adding the trailing semicolon fixes
both problems.

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads