fix(daemon): refuse to poll on an empty label-trigger match (#529)

GitHub's issues-list API treats an empty label filter as no filter at
all, so dispatch.trigger = "label"/"either" with cfg.Label unset
silently returned every open issue in the repo. A live incident
(GH#445) queued 124 unrelated issues in one poll cycle after
[dispatch.labels] -- a different field mapping task states to their
own labels -- was configured while the actual trigger-match label was
left blank.

pollIssuesWithConfig's "label" branch now refuses to poll and logs an
error when cfg.Label is empty; pollEitherWithConfig skips only the
label-side poll in that case, still returning assignee matches.
validateDispatch rejects the same misconfiguration at config-load
time. A per-identity gap remains: identities have no Label field of
their own and share the root's, so an identity overriding
dispatch.trigger to "label" isn't caught by validation -- only by
the runtime guard, which is why the runtime guard matters even with
validation in place.

Fixes archie-core-1786637501009-424-5b8332dd / GH#445.
This commit is contained in:
sam authored and GitHub committed 2026-08-20 23:19:53 +10:00
1 parent 8e8f95381d
commit 63d044603c
4 files changed
+103 -1

No files matched your search

+8
View File
@@ -357,6 +357,10 @@ func (d *Daemon) maintainAndDrain(ctx context.Context) {
func (d *Daemon) pollIssuesWithConfig(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo) []forge.Issue {
switch cfg.Dispatch.Trigger {
case "label":
if cfg.Label == "" {
d.Log.Error("label trigger configured with an empty label; refusing to poll (an empty label matches every open issue)", "repo", repo.FullName())
return nil
}
issues, err := fg.IssuesWithLabel(ctx, repo.Owner, repo.Name, cfg.Label)
if err != nil {
d.Log.Error("label poll failed", "repo", repo.FullName(), "err", err)
@@ -388,6 +392,10 @@ func (d *Daemon) pollEitherWithConfig(ctx context.Context, fg forge.Forge, cfg c
out = append(out, is)
}
}
if cfg.Label == "" {
d.Log.Error("either trigger configured with an empty label; skipping the label poll (an empty label matches every open issue)", "repo", repo.FullName())
return out
}
labelled, err := fg.IssuesWithLabel(ctx, repo.Owner, repo.Name, cfg.Label)
if err != nil {
d.Log.Error("label poll failed", "repo", repo.FullName(), "err", err)
+58 -1
View File
@@ -1059,16 +1059,73 @@ func TestPollIssuesWithConfigUsesIdentityScopedDispatch(t *testing.T) {
}
}
// An empty cfg.Label with trigger "label" or "either" must never reach
// IssuesWithLabel: GitHub's issues-list API treats an empty label filter as
// "no filter" and returns every open issue in the repo. A live incident
// (GH#445) queued 124 unrelated issues in one poll cycle this way, after
// [dispatch.labels] (a different, unrelated field for task-state labels) was
// configured while the actual trigger-match label was left unset.
func TestPollIssuesWithConfigRefusesEmptyLabel(t *testing.T) {
tests := []struct {
name string
trigger string
}{
{name: "label trigger", trigger: "label"},
{name: "either trigger", trigger: "either"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
fg := &recordingForge{}
d := &Daemon{Cfg: config.NewHolder(config.Config{}), Log: slog.New(slog.DiscardHandler)}
cfg := config.Config{Dispatch: config.Dispatch{Trigger: tc.trigger}} // Label left blank.
issues := d.pollIssuesWithConfig(context.Background(), fg, cfg, config.Repo{Owner: "acme", Name: "shared"})
if issues != nil {
t.Fatalf("issues = %v, want nil when label is unset", issues)
}
if len(fg.labelled) != 0 {
t.Fatalf("IssuesWithLabel called with %v, want no call at all (empty label matches every open issue)", fg.labelled)
}
})
}
}
// The "either" trigger must keep polling by assignee when the label is
// empty -- only the label side is unsafe, not the assignee side. A prior
// version of this guard passed even when the empty-label branch dropped
// assignee matches too (return nil instead of return out), because the
// fixture always returned nil from AssignedIssues regardless.
func TestPollIssuesWithConfigEitherTriggerKeepsAssigneeMatchesWhenLabelEmpty(t *testing.T) {
fg := &recordingForge{assignedIssues: []forge.Issue{{Number: 7}}}
d := &Daemon{Cfg: config.NewHolder(config.Config{}), Log: slog.New(slog.DiscardHandler)}
cfg := config.Config{BotUser: "archie", Dispatch: config.Dispatch{Trigger: "either"}} // Label left blank.
issues := d.pollIssuesWithConfig(context.Background(), fg, cfg, config.Repo{Owner: "acme", Name: "shared"})
if len(issues) != 1 || issues[0].Number != 7 {
t.Fatalf("issues = %v, want the one assignee-matched issue preserved", issues)
}
if len(fg.labelled) != 0 {
t.Fatalf("IssuesWithLabel called with %v, want no call at all (empty label matches every open issue)", fg.labelled)
}
}
// recordingForge records the bot user/label passed to the discovery calls
// so tests can assert identity-scoped polling. Everything else panics.
type recordingForge struct {
assigned []string
labelled []string
// assignedIssues is returned by AssignedIssues, letting tests confirm
// assignee matches survive alongside (or despite) the label poll.
assignedIssues []forge.Issue
}
func (f *recordingForge) AssignedIssues(_ context.Context, _, _, botUser string) ([]forge.Issue, error) {
f.assigned = append(f.assigned, botUser)
return nil, nil
return f.assignedIssues, nil
}
func (f *recordingForge) IssuesWithLabel(_ context.Context, _, _, label string) ([]forge.Issue, error) {
@@ -106,10 +106,20 @@ func validateAgent(cfg *config.Config) error {
return nil
}
// validateDispatch rejects a "label" or "either" trigger left with no label
// to match. GitHub's issues-list API treats an empty label filter as no
// filter at all and returns every open issue in the repo -- a live incident
// (GH#445) queued 124 unrelated issues in one poll cycle this way, after
// [dispatch.labels] (a different field, mapping task states to their own
// labels) was configured while the actual trigger-match label was left
// blank.
func validateDispatch(cfg *config.Config) error {
if !oneOf(cfg.Dispatch.Trigger, dispatchTriggers) {
return fmt.Errorf("%w: dispatch.trigger %q (want %s)", ErrInvalidInput, cfg.Dispatch.Trigger, list(dispatchTriggers))
}
if (cfg.Dispatch.Trigger == dispatchTriggerLabel || cfg.Dispatch.Trigger == dispatchTriggerEither) && cfg.Label == "" {
return fmt.Errorf("%w: label is required when dispatch.trigger is %q (an empty label matches every open issue)", ErrInvalidInput, cfg.Dispatch.Trigger)
}
return nil
}
@@ -88,6 +88,33 @@ func TestValidate_RejectsTheSameProblemsAsLoaderLoad(t *testing.T) {
mutate: func(cfg *config.Config) { cfg.Dispatch.Trigger = "not-a-real-trigger" },
wantErr: true,
},
{
// GH#445: an empty label matches every open issue via the forge
// API's issues-list filter, so a "label" trigger with no label
// set must fail validation rather than queue the whole repo.
name: "label trigger with empty label",
mutate: func(cfg *config.Config) {
cfg.Dispatch.Trigger = "label"
cfg.Label = ""
},
wantErr: true,
},
{
name: "either trigger with empty label",
mutate: func(cfg *config.Config) {
cfg.Dispatch.Trigger = "either"
cfg.Label = ""
},
wantErr: true,
},
{
name: "label trigger with a label set",
mutate: func(cfg *config.Config) {
cfg.Dispatch.Trigger = "label"
cfg.Label = "archie"
},
wantErr: false,
},
{
name: "unrecognised forge.type",
mutate: func(cfg *config.Config) { cfg.Forge.Type = "not-a-real-forge" },