fix: reject syntax injection in generic Copy literals
5 files changed,
+39
−1
docs/superpowers/specs/2026-11-13-copy-specialist-design.md+3 −1internal/copydesk/contract.go+3 −0internal/copydesk/contract_test.go+6 −0internal/copydesk/copy.go+10 −0internal/copydesk/copy_test.go+17 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-11-13-copy-specialist-design.md b/docs/superpowers/specs/2026-11-13-copy-specialist-design.md| index 311c46a0..b0907803 100644 |
| --- a/docs/superpowers/specs/2026-11-13-copy-specialist-design.md |
| +++ b/docs/superpowers/specs/2026-11-13-copy-specialist-design.md |
| @@ -73,7 +73,9 @@ judgement, never treated as no strings. Docs-only or successfully parsed |
| logic-only changes skip the model. Generic sessions also receive structured strings in an empty model workspace. |
| The runner applies only literal contents at extractor-reported byte ranges, |
| reconstructs the expected file and requires byte equality. No new |
| -files, logic, tests or bookkeeping changes are permitted there. |
| +files, logic, tests or bookkeeping changes are permitted there. Literal |
| +delimiters, escapes and new template interpolation cannot be introduced by |
| +a replacement; generic template expressions require a contract. |
| A Copy commit becomes `progress.candidate`, rather than using |
| `eng.CandidateSHA` after Copy. Old Checks and Review no longer count. No-edit |
diff --git a/internal/copydesk/contract.go b/internal/copydesk/contract.go| index 7e584321..3aa98ba9 100644 |
| --- a/internal/copydesk/contract.go |
| +++ b/internal/copydesk/contract.go |
| @@ -156,6 +156,9 @@ func Generic(name string, before, after []byte) ([]Literal, error) { |
| return nil, errors.New("copy: unterminated literal") |
| } |
| text := string(raw[start:i]) |
| + if q == '`' && strings.Contains(text, "${") { |
| + return nil, errors.New("copy: template expressions need a contract") |
| + } |
| if strings.Contains(text, "\\") { |
| return nil, errors.New("copy: escaped generic literal needs contract") |
| } |
diff --git a/internal/copydesk/contract_test.go b/internal/copydesk/contract_test.go| index 86190df5..a063a771 100644 |
| --- a/internal/copydesk/contract_test.go |
| +++ b/internal/copydesk/contract_test.go |
| @@ -43,3 +43,9 @@ func TestGenericUnquotedDisplayIsUnknown(t *testing.T) { |
| t.Fatal("unquoted display text skipped") |
| } |
| } |
| + |
| +func TestGenericTemplateExpressionsNeedContract(t *testing.T) { |
| + if _, err := Generic("view.js", []byte("const label=`Old words`"), []byte("const label=`Hi ${(()=>{run()})()}`")); err == nil { |
| + t.Fatal("template expression exposed as editable wording") |
| + } |
| +} |
diff --git a/internal/copydesk/copy.go b/internal/copydesk/copy.go| index cb509e5a..ea085919 100644 |
| --- a/internal/copydesk/copy.go |
| +++ b/internal/copydesk/copy.go |
| @@ -132,6 +132,16 @@ func ValidateScope(before, after []byte, locations []Literal, r Review) error { |
| return errors.New("copy: stale location") |
| } |
| w := byKey[s.Key] |
| + if s.Start < 1 || s.End >= len(before) { |
| + return errors.New("copy: missing literal delimiters") |
| + } |
| + delimiter := before[s.Start-1] |
| + if before[s.End] != delimiter || !strings.ContainsRune("\"'`", rune(delimiter)) { |
| + return errors.New("copy: stale literal delimiters") |
| + } |
| + if strings.ContainsRune(w.Text, rune(delimiter)) || strings.ContainsAny(w.Text, "\\\n\r") || strings.Contains(w.Text, "${") { |
| + return errors.New("copy: unsafe literal contents") |
| + } |
| if w.Action != "accept" { |
| return errors.New("copy: meaning needs answer") |
| } |
diff --git a/internal/copydesk/copy_test.go b/internal/copydesk/copy_test.go| index 62064345..9f8c3217 100644 |
| --- a/internal/copydesk/copy_test.go |
| +++ b/internal/copydesk/copy_test.go |
| @@ -118,3 +118,20 @@ func TestCopyBookkeepingSkipsModelOnlyWithRecords(t *testing.T) { |
| t.Fatal("matching record did not skip model") |
| } |
| } |
| + |
| +func TestGenericScopeRejectsLiteralInjection(t *testing.T) { |
| + for _, tc := range []struct { |
| + before, text string |
| + start, end int |
| + }{{"show('Old words')", "New'); run(); ('", 6, 15}, {"show(`Old words`)", "New ${(()=>{run()})()}", 6, 15}} { |
| + t.Run(tc.before, func(t *testing.T) { |
| + before := []byte(tc.before) |
| + after := append(append(append([]byte{}, before[:tc.start]...), []byte(tc.text)...), before[tc.end:]...) |
| + ex := []Literal{{Key: "k", Text: "Old words", Start: tc.start, End: tc.end}} |
| + review := Review{Version: 1, Strings: []Wording{{Key: "k", Text: tc.text, Action: "accept"}}} |
| + if ValidateScope(before, after, ex, review) == nil { |
| + t.Fatalf("literal injection accepted: %s", tc.text) |
| + } |
| + }) |
| + } |
| +} |