Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(labels): reject control characters in label names (#4531)

Ryan Yubea028784ac8
diff --git a/server/internal/handler/label.go b/server/internal/handler/label.go
index adf7fa6b16..6fc577eaa0 100644
--- a/server/internal/handler/label.go
+++ b/server/internal/handler/label.go
@@ -7,6 +7,8 @@ import (
"net/http"
"regexp"
"strings"
+ "unicode"
+ "unicode/utf8"
"github.com/go-chi/chi/v5"
"github.com/jackc/pgx/v5"
@@ -83,16 +85,18 @@ const maxLabelNameLen = 32
// validateLabelName trims and validates a label name. Returns the trimmed
// name or an error suitable for a 400 response.
func validateLabelName(raw string) (string, error) {
+ for _, r := range raw {
+ if unicode.IsControl(r) {
+ return "", errors.New("name cannot contain tabs, newlines, or control characters")
+ }
+ }
name := strings.TrimSpace(raw)
if name == "" {
return "", errors.New("name is required")
}
- if len(name) > maxLabelNameLen {
+ if utf8.RuneCountInString(name) > maxLabelNameLen {
return "", errors.New("name must be 32 characters or fewer")
}
- // TODO(labels): consider restricting to a charset that excludes newlines,
- // tabs, and control characters. Emoji are left allowed — users can pick
- // `🐛 bug` if they want. Tracked as a follow-up so we don't gate this PR.
return name, nil
}
diff --git a/server/internal/handler/label_test.go b/server/internal/handler/label_test.go
index c5942ec2b2..8dbcb6a2bc 100644
--- a/server/internal/handler/label_test.go
+++ b/server/internal/handler/label_test.go
@@ -339,7 +339,7 @@ func TestAttachLabelCrossWorkspaceLabel(t *testing.T) {
}
}
-// TestLabelNameTooLong — names longer than 64 chars must return 400.
+// TestLabelNameTooLong — names longer than 32 chars must return 400.
func TestLabelNameTooLong(t *testing.T) {
longName := strings.Repeat("a", 33)
w := httptest.NewRecorder()
@@ -361,7 +361,7 @@ func TestLabelNameTooLong(t *testing.T) {
})
testHandler.CreateLabel(w, req)
if w.Code != http.StatusCreated {
- t.Fatalf("CreateLabel 64-char name: expected 201, got %d: %s", w.Code, w.Body.String())
+ t.Fatalf("CreateLabel 32-char name: expected 201, got %d: %s", w.Code, w.Body.String())
}
var created LabelResponse
json.NewDecoder(w.Body).Decode(&created)
@@ -373,6 +373,72 @@ func TestLabelNameTooLong(t *testing.T) {
})
}
+func TestLabelNameRejectsControlCharacters(t *testing.T) {
+ cases := []struct {
+ name string
+ body map[string]any
+ call func(*httptest.ResponseRecorder, *http.Request)
+ }{
+ {
+ name: "create newline",
+ body: map[string]any{"name": "bug\nurgent", "color": "#123456"},
+ call: func(w *httptest.ResponseRecorder, req *http.Request) {
+ testHandler.CreateLabel(w, req)
+ },
+ },
+ {
+ name: "create tab",
+ body: map[string]any{"name": "bug\turgent", "color": "#123456"},
+ call: func(w *httptest.ResponseRecorder, req *http.Request) {
+ testHandler.CreateLabel(w, req)
+ },
+ },
+ {
+ name: "update control",
+ body: map[string]any{"name": "bug\u0000urgent"},
+ call: func(w *httptest.ResponseRecorder, req *http.Request) {
+ req = withURLParam(req, "id", "00000000-0000-0000-0000-000000000000")
+ testHandler.UpdateLabel(w, req)
+ },
+ },
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ w := httptest.NewRecorder()
+ req := newRequest("POST", "/api/labels", tc.body)
+ tc.call(w, req)
+ if w.Code != http.StatusBadRequest {
+ t.Fatalf("expected 400, got %d: %s", w.Code, w.Body.String())
+ }
+ })
+ }
+}
+
+func TestLabelNameAllowsEmoji(t *testing.T) {
+ w := httptest.NewRecorder()
+ req := newRequest("POST", "/api/labels", map[string]any{
+ "name": "🐛 bug",
+ "color": "#123456",
+ })
+ testHandler.CreateLabel(w, req)
+ if w.Code != http.StatusCreated {
+ t.Fatalf("CreateLabel emoji name: expected 201, got %d: %s", w.Code, w.Body.String())
+ }
+
+ var created LabelResponse
+ json.NewDecoder(w.Body).Decode(&created)
+ if created.Name != "🐛 bug" {
+ t.Fatalf("CreateLabel emoji name: got %q", created.Name)
+ }
+ t.Cleanup(func() {
+ w := httptest.NewRecorder()
+ req := newRequest("DELETE", "/api/labels/"+created.ID, nil)
+ req = withURLParam(req, "id", created.ID)
+ testHandler.DeleteLabel(w, req)
+ })
+}
+
// TestColorCaseNormalization — input `#ABCDEF` must be stored as `#abcdef`
// so the case-insensitive uniqueness and downstream CSS rendering are
// consistent. Also accepts a bare `ABCDEF` (no leading #).