🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #82026

Re: Spaces in NNTP commands

#82026
From: Curt Welch
Date: Sun, 18 Oct 2009 23:30
180 lines
10150 bytes
"D. Stussy" <replies@newsgroups.kd6lvw.ampr.org> wrote:
> "Curt Welch" <curt@kcwc.com> wrote in message
> news:20091018102618.742$eW@newsreader.com...
> > =?iso-8859-15?Q?Julien_=C9LIE?= <iulius@nom-de-mon-site.com.invalid>
> wrote:
> > > Hi,
> > >
> > > Is it OK to just discard empty NNTP commands or commands containing
> > > only white spaces?
> >
> > I have no clue what the specs they have written on this recently say,
> > but all NNTP servers I've used, or written, always ignored empty lines.
> > I
> use
> > NNTP servers as command shells interactively and I like my command
> servers
> > to not bitch at me just because I hit return. :)
> >
> > My server had about 20 private NNTP commands for server admin and
> > monitoring so the way I controlled my servers were to telnet to them
> > and type commands.  I didn't use a separate out of band protocol to
> > admin my servers like inn and diablo does.  And since I did spend a lot
> > of time typing commands by hand to the servers, I wanted them to act
> > like a
> normal
> > command shell - which ignores blank lines.
> >
> > Real NNTP clines don't send
> > > That is to say answering nothing to "\r\n" and "   \r\n", just
> > > waiting for the following real command.
> > >
> > > It is what nnrpd currently does for empty commands (but not innd,
> > > which accepts the first "\r\n" and rejects the second "\r\n" with
> > > 500).
> > >
> > > An amusing thing is to write " \r\n" to nnrpd:  it closes the
> connection
> > > :)
> > >
> > > if (ac == 0)
> > >   break;
> > > => leave the infinite read loop
> > > (it should be a "continue")
> > >
> > > N.B.: Even though RFC 3977 does not accept " POST" (leading space),
> > > "POST " (trailing space), "IHAVE  <mid>" (with two white spaces),
> > > it seems better to accept such commands, as nnrpd currently does.
> > >
> > > And just silently read empty commands.
> > >
> > > Any thought about that?
> >
> > Again, all the NNTP servers I've used or written, act like a command
> shell
> > and allow extra spaces everywhere, including in front of the commands
> > or after the last argument.  Command parsing works by breaking the line
> > into an argc/argv like structure based on spaces so it simply allows
> > spaces everywhere around the words that make up the command.
> >
> > The one exception I had to deal with for that is allowing spaces in
> message
> > ids. I would reject the message as invalid if it had a space in the MID
> but
> > I had to hack the parser to special case commands that took message-ids
> as
> > arguments and parse them correctly if it had a space in it.  That was
> back
> > in the day where Diablo actually allowed message-ids like that and
> because
> > of that, I was at times, receiving messages from peers that had a space
> in
> > the message-id.
>
> Is a space in a message-ID even a valid character?

Nope, they never have been.  But yet, Diablo at one time (15 years ago)
would allow them, and would pass them along to other sites, and there were
people generating them.  If you didn't handle it correctly the feed coming
from the diablo server that tried to send it to you, would hang and would
stop feeding you new articles).  Which meant that if one guy somewhere on
Usenet, injected an article that had a Message-ID with a space, all your
diablo peers would get it (from their diablo peers) and try to send it to
you.  If your software didn't receive it, and reject it correctly, all your
peers that ran diablo would stop sending you new articles because they
would keep trying to send you the bad article over and over again.  So one
guy, someone on Usenet, injecting a bad message-id article, could shut down
a good number of your peers if your software didn't deal correctly with
that type of invalid message-id.  You didn't have to accept the article,
but you did have to correctly receive the entire thing from the peer, and
correctly send back a reject message with the correct (aka invalid)
message-id on it so the sending diablo would remove it from the queue and
not get stuck trying to send it to you over and over.

> A space is not part of the character set allowed by "atext" (from the
> BNF) nor "qtext" (for quoted strings) nor "dtext".  Message-ID
> technically relies only on "atext" and "dtext".  Therefore, I conclude
> that spaces are NOT allowed in message ID's, even inside a quoted string
> (if such were allowed in a MID).
>
> Although the original news message format borrowed much from RFC 822, I
> have used its current replacement, RFC 5322, for reference.  Section
> 3.6.4 of 5322 contains the BNF syntax for a message-id field.
>
> Note also that a message-id is supposed to have a guarentee of
> uniqueness. Therefore, MIDs like <...@localhost> are INVALID - for
> violating the uniqueness property (and similarly with any other reserved
> domain entry). (Yes, there are people that do send messages with the
> domain-part set to "localhost" or "example.com" and the like.  In my
> cleanfeed.local file, I add these to the filtered out MIDs as such
> messages are considered malformed and thus SPAM).

It's physically impossible to guarantee uniqueness with 100% accuracy.  To
do so, would require machines that ran with 100% reliability and software
developers that wrote code with 100% guarantee of accuracy - both of which
is impossible.

In truth, what we have to live with, is to reduce the odds of collision to
some acceptable level (which has never been formally defined in an RFC as
far as I know).  However, "acceptable level" on Usenet, is actually not
hard at all.  The fact that a message posted to Usenet might get lost, is
really not all that important.  It happens all the time for lots of
different reasons.  If we lose a few messages a day out of millions, that's
more than good enough for all practical issues.  Usenet still works fine
even if a loss rate that high.  As such, any system for generating message
ids simply has to work well enough so that the number of articles lost due
to MID collisions is some safe level below the typical rate at which
articles are lost on Usenet due to all other reasons.  That is, if we are
loosing one message because of MID collision, for every 1000 lost for every
reason, that extra 1 out of 1000 isn't all that bad.

If that acceptable level is chosen to be 1 out of 10^10 (just to pick some
small number out of my ass), then you can generate message IDs using a
hashing system that reduces the odds of collision to that level.  A random
hash with approximately twice the number of bits needed to produce 10^10
values will get you in the ball park.  Or 2log2(10*10) or about 67 bits of
"good" random data.  If you can put 6 bits per MID character we are talking
about 10 digits of random characters in a message id that ends with
@localhost to reduce the odds of collision to a level that is good enough
to allow Usenet to work as expected.

So, if the rest of the MID is generated correctly, ending in @localhost is
not strictly so bad.  However, most message-ids ending in @localhost do so
because of poorly configured or designed systems which aren't generating
the rest of the ID in a way to make up for the error so using that as a
strong indicator of a poor quality article (spam) is probably fine.

> > This was required for "TAKETHIS <bad id>".  If you rejected it as an
> > invalid command, you break the protocol when the sending site follows
> that
> > with a full article. You want to correctly take the article from the
> > peer and then correctly reject it.  If you don't do that, the peer just
> > gets hung as it keeps trying to send the article to you again without
> > understanding why it's getting 500 errors from your server - which
> > means your feed from that peer might just hang until someone on the
> > sending
> side
> > manually takes the bad article out of the queue.
>
> If there's a space, it should be rejected with the error appropriate to a
> bad parameter, not a bad command.
>
> > I would hope current Diablo (and no other current NNTP servers) do that
> > anymore.  But it's one more bit of old code that was needed once, and
> could
> > be useful in the future when someone writes a cheap ass server that
> allows
> > spaces in Message-ids and tries to feed such articles to a peer.
>
> As long as we're dealing with NNTP command parsing, should a PASSWORD or
> USER-ID be permitted to contain a space?  Unlike that with MID, I'm not
> certain I've seen anything that would intentionally disallow such.

Mine don't support it.  I don't know if any do.  I don't think there's any
reason to require NNTP servers to support it - at least not for AUTHINFO
commands.  If you want to define a new auth system that does support it,
that's fine.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                                        http://NewsReader.Com/
Technical Details
Message-ID: <20091018192439.686$0R@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!not-for-mail
References: <hbdap8$7e8$1@news.trigofacile.com> <20091018102618.742$eW@newsreader.com> <hbg3qj$8bf$1@snarked.org>

Show Full Headers
Complete Article Headers
Message-ID: <20091018192439.686$0R@newsreader.com>
Subject: Re: Spaces in NNTP commands
Date: Sun, 18 Oct 2009 23:30:33 +0000
From: curt@kcwc.com (Curt Welch)
References: <hbdap8$7e8$1@news.trigofacile.com> <20091018102618.742$eW@newsreader.com> <hbg3qj$8bf$1@snarked.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-NRC-Trace: NewsReader.Com 1NEgId5ZYIx74p/isOC3-y6ttJ0FR0UoK-6+kvLiFV_pSse3PQ
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,
 ?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
 %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 180
NNTP-Posting-Host: 45d38402.nr5-q1.newsreader.com
X-Trace: DXC=54MmgSUQYgDHVEe9MOX; EMbgZaH`e<A[IZ?:i9<JJBSNhKl@n^LQ1kGiJ;
 iV2YAoGE0F3WoQL<AiH]5ZFMG:YBlB
X-Complaints-To: abuse@newsreader.com