From 657d7879aa90e1c656239ec7dc4390e813552fc2 Mon Sep 17 00:00:00 2001 From: "Wilhelmina \"Willow\" Poortenga" <156546731+wittywilla@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:37:44 -0500 Subject: [PATCH 1/3] Store text refuses hidden characters; manifest names are plain text; fuzz the parsers plainText now refuses C1 controls and invisible direction and zero-width characters, and a manifest's name goes through the same check. Fuzz tests for the catalogue, its signature check, manifests, withdrawals lists and integration.json. Co-Authored-By: Claude Opus 5.5 --- catalog.go | 21 ++++++++- fuzz_test.go | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ manifest.go | 2 + 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 fuzz_test.go diff --git a/catalog.go b/catalog.go index 3ae4176..73281e6 100644 --- a/catalog.go +++ b/catalog.go @@ -17,6 +17,7 @@ import ( "sort" "strings" "time" + "unicode" "unicode/utf8" ) @@ -485,13 +486,31 @@ func plainText(s string, limit int, lines bool) bool { return false } for _, r := range s { - if r == 0x7f || (r < ' ' && !(lines && (r == '\n' || r == '\t'))) { + if lines && (r == '\n' || r == '\t') { + continue + } + // Control characters (C0, DEL and C1), and the invisible ones that turn text round + // or hide what it says: a name that reads as another module's must not be possible. + if unicode.IsControl(r) || hiddenRune(r) { return false } } return true } +// hiddenRune is a character that changes how text around it is shown without being seen: +// direction marks, embeddings, overrides and isolates, and zero-width spaces. The joiners +// emoji are made with (U+200C, U+200D) stay allowed. +func hiddenRune(r rune) bool { + switch { + case r == 0x061c, r == 0x200b, r == 0x200e, r == 0x200f, r == 0x2060, r == 0xfeff: + return true + case r >= 0x202a && r <= 0x202e, r >= 0x2066 && r <= 0x2069: + return true + } + return false +} + // Find looks a module up. func (c *Catalog) Find(id string) *CatalogModule { for i := range c.Modules { diff --git a/fuzz_test.go b/fuzz_test.go new file mode 100644 index 0000000..60fa129 --- /dev/null +++ b/fuzz_test.go @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +// Copyright (C) 2026 WittyWilla and contributors + +package wittymodule + +import ( + "crypto/ed25519" + "encoding/base64" + "os" + "path/filepath" + "strings" + "testing" +) + +// Everything a server reads from a catalogue, a release or a withdrawals list is parsed +// before anyone has looked at it. None of it may panic, and what is accepted must be valid. + +func seedJSON(f *testing.F, pattern string) { + f.Helper() + files, _ := filepath.Glob(pattern) + for _, p := range files { + if b, err := os.ReadFile(p); err == nil && len(b) < 1<<20 { + f.Add(b) + } + } + f.Add([]byte(`{}`)) + f.Add([]byte(`{"format":1,"name":"x","serial":1,"generated":"2026-01-01T00:00:00Z","modules":[]}`)) + f.Add([]byte(`[`)) +} + +func FuzzParseCatalog(f *testing.F) { + seedJSON(f, "testdata/*catalog*.json") + f.Fuzz(func(t *testing.T, b []byte) { + c, err := ParseCatalog(b) + if err != nil { + return + } + if err := c.Validate(); err != nil { + t.Fatalf("accepted, then invalid: %v", err) + } + }) +} + +func FuzzVerifyCatalog(f *testing.F) { + pub, priv, _ := ed25519.GenerateKey(nil) + raw := []byte(`{"format":1,"name":"x","serial":1,"generated":"2026-01-01T00:00:00Z","modules":[]}`) + good := base64.StdEncoding.EncodeToString(ed25519.Sign(priv, raw)) + f.Add(raw, []byte(good)) + f.Add(raw, []byte("AAAA")) + f.Fuzz(func(t *testing.T, b, sig []byte) { + c, err := VerifyCatalog(b, sig, []ed25519.PublicKey{pub}) + if err != nil { + return + } + s, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(sig))) + if !ed25519.Verify(pub, b, s) || c == nil { + t.Fatal("a catalogue the key didn't sign was taken") + } + }) +} + +func FuzzParseManifest(f *testing.F) { + seedJSON(f, "testdata/*.json") + f.Add([]byte(`{"id":"x","name":"X","version":"1.0.0","repo":"a/b","api":5,"minServer":"0.8.0","maxServer":"0.8.x","entry":"x"}`)) + f.Fuzz(func(t *testing.T, b []byte) { + m, err := ParseManifest(b) + if err != nil || m == nil { + return + } + if !plainText(m.Name, 64, false) { + t.Fatalf("a manifest named %q was taken", m.Name) + } + }) +} + +func FuzzParseWithdrawals(f *testing.F) { + f.Add([]byte(`{"module":"x","serial":1,"versions":[{"version":"1.0.0","severity":"security","reason":"r"}]}`)) + f.Fuzz(func(t *testing.T, b []byte) { + w, err := ParseWithdrawals(b) + if err != nil || w == nil { + return + } + for _, v := range w.Versions { + _ = w.Find(v.Version) + } + }) +} + +func FuzzParseIntegration(f *testing.F) { + seedJSON(f, "testdata/*integration*.json") + f.Fuzz(func(t *testing.T, b []byte) { _, _ = ParseIntegration(b) }) +} + +func TestPlainTextRefusesHiddenCharacters(t *testing.T) { + r := func(c rune) string { return string(c) } + for _, s := range []string{ + "Witty" + r(0x202e) + "Tuner", "WittyTuner" + r(0x200b), r(0x2066) + "WittyTuner" + r(0x2069), "Witty" + r(0x85) + "Tuner", + "Witty" + r(0x9b) + "Tuner", r(0xfeff) + "WittyTuner", "a" + r(0x61c) + "b", "Witty" + r(0x7f), + } { + if plainText(s, 64, false) || plainText(s, 64, true) { + t.Errorf("%q was taken as plain text", s) + } + } + family := r(0x1f468) + r(0x200d) + r(0x1f469) + r(0x200d) + r(0x1f467) + " Family" + for _, s := range []string{"WittyTuner", "Caf" + r(0xe9) + " T" + r(0xe9) + "l" + r(0xe9), r(0x65e5) + r(0x672c) + r(0x8a9e), family} { + if !plainText(s, 64, false) { + t.Errorf("%q was refused", s) + } + } + if !plainText("line one"+r(10)+"line two"+r(9)+"end", 64, true) || plainText("line one"+r(10)+"line two", 64, false) { + t.Error("new lines are for long text only") + } +} + +func TestManifestNameIsPlainText(t *testing.T) { + m := Manifest{ID: "x", Name: "Witty" + string(rune(0x202e)) + "Tuner", Version: "1.0.0", Repo: "a/b", API: 5, MinServer: "0.8.0", MaxServer: "0.8.x", Entry: "x"} + found := false + for _, p := range m.Problems() { + if p.Field == "name" { + found = true + } + } + if !found { + t.Fatal("a manifest name with a direction override was taken") + } +} diff --git a/manifest.go b/manifest.go index 14cff12..787cc09 100644 --- a/manifest.go +++ b/manifest.go @@ -225,6 +225,8 @@ func (m *Manifest) Problems() []Problem { } if m.Name == "" { bad("name", "no name") + } else if !plainText(m.Name, 64, false) { + bad("name", "the name must be one line of plain text, at most 64 bytes, with no hidden characters") } if !Valid(m.Version) { bad("version", "%q is not a version", m.Version) From b649f629491e5436d407fa80681fdd137cfc5f6a Mon Sep 17 00:00:00 2001 From: "Wilhelmina \"Willow\" Poortenga" <156546731+wittywilla@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:04:15 -0500 Subject: [PATCH 2/3] CI: pin setup-node by commit, as every other action is Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49386fa..b2d7bb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: go mod tidy -diff - run: go vet ./... - run: go test ./... -count=1 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 with: node-version: 24 - name: The TypeScript kit for modules' SDUI From 28caaed5d153833ea1d9b5c87162a895a5f30219 Mon Sep 17 00:00:00 2001 From: "Wilhelmina \"Willow\" Poortenga" <156546731+wittywilla@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:39:18 -0500 Subject: [PATCH 3/3] Bump the version for the change since the last release Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ module.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 482d515..2bf5858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ What changed in WittyModule, newest first. What changed before it had a repository of its own is in the [WittyMediaServer changelog](https://github.com/wittywilla/WittyMediaServer/blob/master/CHANGELOG.md). +## Unreleased + +- **WittyModule 0.5.6:** Store and manifest text refuse hidden control and direction characters, and a module's name is checked like the rest. Fuzz tests for the catalogue, manifests, withdrawals and integration files. + ## 0.5.5 - SDUI core synced from the server (a focusable list's rows stay focus stops; a List's rows carry their items' buttons). Text files are checked out with LF, and module-kit gives every module a .gitattributes that says so (#7). diff --git a/module.json b/module.json index 3912bf5..cf8cd53 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "id": "wittymodule", "name": "WittyModule", - "version": "0.5.5", + "version": "0.5.6", "license": "AGPL-3.0-or-later", "repo": "wittywilla/WittyModule", "delivery": "library",