NNTP: OVER and HDR by Message-ID only for newsgroup articles

selectRange (OVER, HDR) looked up a Message-ID without checking that its
area is a newsgroup, as selectArticle does, so OVER <id> answered for a
message in an area out of news, confirming it.  Both now find articles by
Message-ID through byMessageID: a newsgroup's, visible to the session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
This commit is contained in:
Claude committed 2026-10-18 21:42:32 +00:00
1 parent f069d2822d
commit 0d71e77e48
2 files changed
+42 -12

No files matched your search

+22
View File
@@ -418,3 +418,25 @@ func TestIHAVE(t *testing.T) {
t.Fatalf("%+v, %v", m, err)
}
}
// TestMessageIDOutsideNews: a message whose area is no newsgroup (taken out
// of news after it was posted) is no article by its Message-ID, to OVER and
// HDR as to ARTICLE: the reader learns nothing of it.
func TestMessageIDOutsideNews(t *testing.T) {
s := newSite(t, "news.a.test", ServerSettings{}, nil)
m := s.post(t, "alice", "Not news now", "hush", 0)
if m.MessageID == "" {
t.Fatal("no Message-ID")
}
cv := dialConv(t, s.addr)
cv.send("OVER " + m.MessageID)
cv.expect("224") // news, for now
cv.block()
if err := s.b.Store.SetNewsgroup(s.area.ID, ""); err != nil {
t.Fatal(err)
}
for _, cmd := range []string{"OVER ", "HDR Subject ", "ARTICLE ", "STAT "} {
cv.send(cmd + m.MessageID)
cv.expect("430")
}
}
+20 -12
View File
@@ -645,16 +645,29 @@ func (ss *session) nextLast(next bool) {
ss.reply(223, fmt.Sprintf("%d %s", m.ID, m.MessageID))
}
// byMessageID is the article with Message-ID id, if it is in a newsgroup
// this session may read: nil otherwise, however it is not (no such
// message, one in an area that is no newsgroup, or one not visible here),
// so that a client learns nothing of messages it may not read.
func (ss *session) byMessageID(id string) *store.Message {
st := ss.s.Svc.B.Store
m, err := st.MessageByMessageID(id)
if err != nil || m.MessageID == "" {
return nil
}
if a, err := st.Area(m.AreaID); err != nil || a.Newsgroup == "" || !ss.visible(a) {
return nil
}
return m
}
// selectArticle finds the article an ARTICLE-like command names: by
// Message-ID (number 0), by number in the group, or the current one.
func (ss *session) selectArticle(args []string) (*store.Message, int64, bool) {
st := ss.s.Svc.B.Store
if len(args) > 0 && strings.HasPrefix(args[0], "<") {
m, err := st.MessageByMessageID(args[0])
if err == nil {
if a, err := st.Area(m.AreaID); err == nil && a.Newsgroup != "" && ss.visible(a) {
return m, 0, true
}
if m := ss.byMessageID(args[0]); m != nil {
return m, 0, true
}
ss.reply(430, "No article with that message-id")
return nil, 0, false
@@ -743,13 +756,8 @@ func overview(raw []byte) (map[string]string, int, int) {
func (ss *session) selectRange(args []string) ([]*store.Message, bool, bool) {
st := ss.s.Svc.B.Store
if len(args) > 0 && strings.HasPrefix(args[0], "<") {
m, err := st.MessageByMessageID(args[0])
if err == nil {
if a, err2 := st.Area(m.AreaID); err2 != nil || !ss.visible(a) {
err = store.ErrNotFound
}
}
if err != nil || m.MessageID == "" {
m := ss.byMessageID(args[0])
if m == nil {
ss.reply(430, "No article with that message-id")
return nil, false, false
}