Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): drop NUL bytes from issue and project text (#10944)
pseudoyu76a4dd4c7c1f
diff --git a/server/internal/handler/handler_test.go b/server/internal/handler/handler_test.goindex fabf067f7a..b696895aca 100644--- a/server/internal/handler/handler_test.go+++ b/server/internal/handler/handler_test.go@@ -1546,6 +1546,77 @@ func TestUpdateIssueAllowsExplicitUnassign(t *testing.T) {}}+func TestCreateIssueRejectsNULOnlyTitle(t *testing.T) {+ var response struct {+ Error string `json:"error"`+ }+ testutil.Call(t, testHandler.CreateIssue, newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{+ "title": "\x00",+ })).Want(http.StatusBadRequest).JSON(&response)+ if response.Error != "title is required" {+ t.Fatalf("error = %q, want title is required", response.Error)+ }+}++// A NUL survives the JSON round trip but PostgreSQL TEXT rejects it, so an+// agent filing tool output that carries one got a 500 and no issue.+func TestIssueTextDropsNULBytes(t *testing.T) {+ var issue IssueResponse+ testutil.Call(t, testHandler.CreateIssue, newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{+ "title": "Build\x00 log", "description": "exit\x00 1",+ })).Want(http.StatusCreated).JSON(&issue)+ t.Cleanup(func() {+ testHandler.DeleteIssue(httptest.NewRecorder(), withURLParam(newRequest("DELETE", "/api/issues/"+issue.ID, nil), "id", issue.ID))+ })+ if issue.Title != "Build log" || issue.Description == nil || *issue.Description != "exit 1" {+ t.Fatalf("create must drop NUL bytes: title=%q description=%v", issue.Title, issue.Description)+ }++ // The bases are compared with the stored text, so they are cleaned too.+ req := withURLParam(newRequest("PUT", "/api/issues/"+issue.ID, map[string]any{+ "title": "Build\x00 log 2", "title_base": "Build\x00 log",+ "description": "exit\x00 2", "description_base": "exit\x00 1",+ }), "id", issue.ID)+ testutil.Call(t, testHandler.UpdateIssue, req).Want(http.StatusOK).JSON(&issue)+ if issue.Title != "Build log 2" || issue.Description == nil || *issue.Description != "exit 2" {+ t.Fatalf("update must drop NUL bytes: title=%q description=%v", issue.Title, issue.Description)+ }++ // A batch write that fails is only logged, so the NUL made it a silent no-op.+ var batch struct {+ Updated int `json:"updated"`+ }+ testutil.Call(t, testHandler.BatchUpdateIssues, newRequest("PATCH", "/api/issues/batch?workspace_id="+testWorkspaceID, map[string]any{+ "issue_ids": []string{issue.ID},+ "updates": map[string]any{"title": "Build\x00 log 3"},+ })).Want(http.StatusOK).JSON(&batch)+ testutil.Call(t, testHandler.GetIssue, withURLParam(newRequest("GET", "/api/issues/"+issue.ID, nil), "id", issue.ID)).Want(http.StatusOK).JSON(&issue)+ if batch.Updated != 1 || issue.Title != "Build log 3" {+ t.Fatalf("batch update must drop NUL bytes: updated=%d title=%q", batch.Updated, issue.Title)+ }+}++func TestProjectTextDropsNULBytes(t *testing.T) {+ var project ProjectResponse+ testutil.Call(t, testHandler.CreateProject, newRequest("POST", "/api/projects?workspace_id="+testWorkspaceID, map[string]any{+ "title": "Road\x00map", "description": "Q\x001",+ })).Want(http.StatusCreated).JSON(&project)+ t.Cleanup(func() {+ testHandler.DeleteProject(httptest.NewRecorder(), withURLParam(newRequest("DELETE", "/api/projects/"+project.ID, nil), "id", project.ID))+ })+ if project.Title != "Roadmap" || project.Description == nil || *project.Description != "Q1" {+ t.Fatalf("create must drop NUL bytes: title=%q description=%v", project.Title, project.Description)+ }++ req := withURLParam(newRequest("PUT", "/api/projects/"+project.ID, map[string]any{+ "title": "Road\x00map 2", "description": "Q\x002",+ }), "id", project.ID)+ testutil.Call(t, testHandler.UpdateProject, req).Want(http.StatusOK).JSON(&project)+ if project.Title != "Roadmap 2" || project.Description == nil || *project.Description != "Q2" {+ t.Fatalf("update must drop NUL bytes: title=%q description=%v", project.Title, project.Description)+ }+}+func TestCommentCRUD(t *testing.T) {// Create an issue firstreq := newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex 05e80161fe..52b14b523d 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -3370,6 +3370,7 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid request body")return}+ req.Title = sanitizeNullBytes(req.Title)if req.Title == "" {writeError(w, http.StatusBadRequest, "title is required")@@ -4024,6 +4025,12 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid request body")return}+ // PostgreSQL TEXT rejects NUL, which survives a JSON round trip. The bases+ // are compared with the stored text, so they are cleaned the same way.+ req.Title = sanitizeNullBytesPtr(req.Title)+ req.TitleBase = sanitizeNullBytesPtr(req.TitleBase)+ req.Description = sanitizeNullBytesPtr(req.Description)+ req.DescriptionBase = sanitizeNullBytesPtr(req.DescriptionBase)// Track which fields were explicitly present in JSON (even if null)var rawFields map[string]json.RawMessage@@ -4826,6 +4833,9 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid request body")return}+ // See UpdateIssue: a failed write here is only logged and skipped.+ req.Updates.Title = sanitizeNullBytesPtr(req.Updates.Title)+ req.Updates.Description = sanitizeNullBytesPtr(req.Updates.Description)if len(req.IssueIDs) == 0 {writeError(w, http.StatusBadRequest, "issue_ids is required")diff --git a/server/internal/handler/project.go b/server/internal/handler/project.goindex 46c337fbef..5d0ce966b8 100644--- a/server/internal/handler/project.go+++ b/server/internal/handler/project.go@@ -343,6 +343,9 @@ func (h *Handler) CreateProject(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid request body")return}+ // PostgreSQL TEXT rejects NUL, which survives a JSON round trip.+ req.Title = sanitizeNullBytes(req.Title)+ req.Description = sanitizeNullBytesPtr(req.Description)if req.Title == "" {writeError(w, http.StatusBadRequest, "title is required")return@@ -667,6 +670,8 @@ func (h *Handler) UpdateProject(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, "invalid request body")return}+ req.Title = sanitizeNullBytesPtr(req.Title)+ req.Description = sanitizeNullBytesPtr(req.Description)var rawFields map[string]json.RawMessagejson.Unmarshal(bodyBytes, &rawFields)diff --git a/server/internal/handler/skill.go b/server/internal/handler/skill.goindex 19875e16cf..40e2b8c29d 100644--- a/server/internal/handler/skill.go+++ b/server/internal/handler/skill.go@@ -42,6 +42,15 @@ func sanitizeNullBytes(s string) string {return util.SanitizeTextForPostgres(s)}+// sanitizeNullBytesPtr is sanitizeNullBytes for an optional request field.+func sanitizeNullBytesPtr(s *string) *string {+ if s == nil {+ return nil+ }+ clean := sanitizeNullBytes(*s)+ return &clean+}+// --- Response structs ---type SkillResponse struct {diff --git a/server/internal/handler/source_context.go b/server/internal/handler/source_context.goindex 9f9db45319..134433d2a9 100644--- a/server/internal/handler/source_context.go+++ b/server/internal/handler/source_context.go@@ -540,6 +540,7 @@ func (h *Handler) CreateCommentSubIssue(w http.ResponseWriter, r *http.Request)writeError(w, http.StatusBadRequest, "issue is required for manual mode")return}+ req.Issue.Title = sanitizeNullBytes(req.Issue.Title)if strings.TrimSpace(req.Issue.Title) == "" {writeJSON(w, http.StatusBadRequest, map[string]any{"code": "invalid_request", "error": "title is required"})return@@ -680,7 +681,7 @@ func (h *Handler) cloneSourceContext(ctx context.Context, workspaceID, userID, c}func (h *Handler) createManualCommentSubIssue(w http.ResponseWriter, r *http.Request, workspaceID, userID pgtype.UUID, input CreateIssueRequest, capture service.SourceContextCapture, limits service.SourceContextLimitUsage) error {- title := strings.TrimSpace(input.Title)+ title := strings.TrimSpace(sanitizeNullBytes(input.Title))if title == "" {return sourceContextBadRequest("title is required")}diff --git a/server/internal/handler/source_context_integration_test.go b/server/internal/handler/source_context_integration_test.goindex 37ac7e0c4c..9eb16b2bf1 100644--- a/server/internal/handler/source_context_integration_test.go+++ b/server/internal/handler/source_context_integration_test.go@@ -14,6 +14,7 @@ import ("github.com/multica-ai/multica/server/internal/events""github.com/multica-ai/multica/server/internal/projectaccess""github.com/multica-ai/multica/server/internal/service"+ "github.com/multica-ai/multica/server/internal/testutil""github.com/multica-ai/multica/server/internal/util""github.com/multica-ai/multica/server/pkg/protocol")@@ -33,6 +34,26 @@ func TestWriteSourceContextErrorHidesInternalDetails(t *testing.T) {}}+func TestCommentSubIssueRejectsNULOnlyTitle(t *testing.T) {+ sourceID := dbfx.Issue(t, "source issue")+ commentID := dbfx.Comment(t, sourceID, "source comment")+ var preview sourceContextPreviewResponse+ testutil.Call(t, testHandler.PreviewCommentSubIssue, withURLParam(newRequest(http.MethodGet,+ "/api/comments/"+commentID+"/sub-issue-preview", nil), "commentId", commentID)).Want(http.StatusOK).JSON(&preview)++ var response struct {+ Error string `json:"error"`+ }+ testutil.Call(t, testHandler.CreateCommentSubIssue, withURLParam(newRequest(http.MethodPost,+ "/api/comments/"+commentID+"/sub-issues", map[string]any{+ "mode": "manual", "capture_token": preview.CaptureToken,+ "issue": map[string]any{"title": " \x00 "},+ }), "commentId", commentID)).Want(http.StatusBadRequest).JSON(&response)+ if response.Error != "title is required" {+ t.Fatalf("error = %q, want title is required", response.Error)+ }+}+func TestCommentSourceContextLifecycle(t *testing.T) {if testHandler == nil || testPool == nil {t.Skip("database not available")diff --git a/server/internal/integrations/channel/engine/issue_command.go b/server/internal/integrations/channel/engine/issue_command.goindex ee454ce781..58a0ae546b 100644--- a/server/internal/integrations/channel/engine/issue_command.go+++ b/server/internal/integrations/channel/engine/issue_command.go@@ -1,6 +1,10 @@package engine-import "strings"+import (+ "strings"++ "github.com/multica-ai/multica/server/internal/util"+)// issueCommandPrefix is the literal command token. We match exactly —// `/Issue` or `/ISSUE` do NOT trigger creation. The case sensitivity is@@ -49,7 +53,7 @@ func ParseIssueCommand(body string) (*IssueCommand, bool) {}}- title := strings.TrimSpace(rest)+ title := strings.TrimSpace(util.SanitizeTextForPostgres(rest))description := ""if firstIdx+1 < len(lines) {description = strings.TrimRight(strings.Join(lines[firstIdx+1:], "\n"), " \t\n")diff --git a/server/internal/integrations/channel/engine/issue_command_test.go b/server/internal/integrations/channel/engine/issue_command_test.goindex 7bce204a5c..89990444df 100644--- a/server/internal/integrations/channel/engine/issue_command_test.go+++ b/server/internal/integrations/channel/engine/issue_command_test.go@@ -14,6 +14,9 @@ func TestParseIssueCommand(t *testing.T) {{"title + description", "/issue Fix login\nIt 500s on submit\nsince Tuesday", true, "Fix login", "It 500s on submit\nsince Tuesday"},{"bare command", "/issue", true, "", ""},{"bare command with trailing space", "/issue ", true, "", ""},+ {"NUL-only title", "/issue \x00", true, "", ""},+ {"NUL-only title with spaces", "/issue \x00 \x00 ", true, "", ""},+ {"NUL in title", "/issue \x00 Fix\x00 login \x00", true, "Fix login", ""},{"leading blank lines", "\n\n/issue Title", true, "Title", ""},{"tab separator", "/issue\tTabbed", true, "Tabbed", ""},{"not a token", "/issuetracker do thing", false, "", ""},diff --git a/server/internal/integrations/channel/engine/router.go b/server/internal/integrations/channel/engine/router.goindex 004594d4dd..a8a1153969 100644--- a/server/internal/integrations/channel/engine/router.go+++ b/server/internal/integrations/channel/engine/router.go@@ -1165,6 +1165,7 @@ func (r *Router) drop(ctx context.Context, set ResolverSet, msg channel.InboundM}func (r *Router) createIssue(ctx context.Context, inst ResolvedInstallation, originType string, creatorUserID, sessionID pgtype.UUID, cmd IssueCommand, issuePrefix string, assignedRunFireAt time.Time) (service.IssueCreateResult, error) {+ cmd.Title = strings.TrimSpace(util.SanitizeTextForPostgres(cmd.Title))if cmd.Title == "" {return service.IssueCreateResult{}, ErrEmptyIssueTitle}diff --git a/server/internal/integrations/channel/engine/router_test.go b/server/internal/integrations/channel/engine/router_test.goindex 1e788eff59..81ff200469 100644--- a/server/internal/integrations/channel/engine/router_test.go+++ b/server/internal/integrations/channel/engine/router_test.go@@ -1394,6 +1394,28 @@ func TestRouter_BareIssueReturnsUsageWithoutCreatingOrResolvingMedia(t *testing.}}+func TestRouter_NULOnlyIssueTitleReturnsUsage(t *testing.T) {+ h := newHarness(t)+ h.binder.parseIssue = true+ msg := p2pMessage(t)+ msg.Text = "/issue \x00 \x00 "+ msg.CommandText = msg.Text+ msg.Type = channel.MsgTypeImage+ if err := h.router.Handle(context.Background(), msg); err != nil {+ t.Fatalf("NUL-only title must return usage, got error: %v", err)+ }+ if h.issues.called || h.tasks.calls() != 0 || h.media.calls() != 0 {+ t.Fatalf("NUL-only title created issue=%v, chat tasks=%d, media resolutions=%d",+ h.issues.called, h.tasks.calls(), h.media.calls())+ }+ if !waitFor(time.Second, func() bool {+ calls := h.replier.calls()+ return len(calls) == 1 && calls[0].Outcome == OutcomeIssueUsage && calls[0].IssueUsageHadMedia+ }) {+ t.Fatalf("issue usage result was not delivered: %+v", h.replier.calls())+ }+}+func TestRouter_BareIssueWithoutMediaDoesNotRequestMediaResend(t *testing.T) {h := newHarness(t)h.binder.parseIssue = truediff --git a/server/internal/service/issue.go b/server/internal/service/issue.goindex 7f96f4c333..4c57aa5593 100644--- a/server/internal/service/issue.go+++ b/server/internal/service/issue.go@@ -231,6 +231,10 @@ type IssueCreateResult struct {// savepoint has to be established before the statement that might fail, so every// successful create would pay for it too.func (s *IssueService) Create(ctx context.Context, p IssueCreateParams, opts IssueCreateOpts) (IssueCreateResult, error) {+ // PostgreSQL TEXT rejects NUL, which survives a JSON round trip. Cleaned+ // here so every create entry stores the same text.+ p.Title = util.SanitizeTextForPostgres(p.Title)+ p.Description.String = util.SanitizeTextForPostgres(p.Description.String)res, err := s.createOnce(ctx, p, opts)if err == nil {return res, nil