Repository navigation
Commit fb859d4
fix(cli): escape registry-supplied text in catalog search and show (#1767)
## Bug
`mcpproxy catalog search` and `mcpproxy catalog show` print
registry-supplied strings (title, id, publisher, description, install
command, required input names) straight to the terminal. The search
table only byte-truncates the title, and `show` prints everything with
`%s`.
These strings come from remote registries (the official registry,
Smithery, custom `registries` entries). An entry whose title or
description contains ANSI escapes can clear or rewrite the operator's
screen. A newline can forge extra table rows next to a real result, for
example a fake `✓ added` line.
`mcpproxy tools list` already escapes upstream-controlled text for this
reason, using `sanitizeCell`/`sanitizeDescriptionCell` and
`detect.CapEvidence` (GH #938). The catalog commands never got the same
treatment.
## Trigger
A registry entry with this title:
```
"\x1b[2J\x1b[1;1HTotally Safe\nofficial trusted http ✓"
```
Running `mcpproxy catalog search <q>` or `mcpproxy catalog show
official/<id>` writes the raw ESC sequences to the tty.
## Fix
Run the registry-supplied fields through the existing helpers:
- `sanitizeDescriptionCell` for prose (the title, which keeps the
40-rune cap, and the description).
- `sanitizeCell` for identifiers (id, publisher, transport, install URL
and command, input names).
Control and format runes are escaped (made visible), not dropped.
JSON/YAML output is unchanged.
## Test
`TestCatalogOutput_EscapesRegistryControlCharacters` renders a poisoned
result through `printCatalogTable` and `renderCatalogShow` and asserts
that neither output contains a raw ESC byte.
## Commands run
- `go vet ./cmd/mcpproxy`: clean
- `go test -count=1 ./cmd/mcpproxy`: ok (cgo build, run locally with
`SDKROOT` set to the macOS 26.5 SDK)
- With the fix reverted (`git stash` of `catalog_cmd.go`), the new test
fails with `search table wrote a raw ESC to the terminal` and `show
wrote a raw ESC to the terminal`.
- `gofmt -l` on the edited files: no output
---------
Co-authored-by: Algis Dumbris <a.dumbris@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent a8adffc commit fb859d4
2 files changed
Lines changed: 123 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
432 | | - | |
| 433 | + | |
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
| |||
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
441 | 481 | | |
442 | 482 | | |
443 | | - | |
444 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
445 | 487 | | |
446 | | - | |
| 488 | + | |
447 | 489 | | |
448 | 490 | | |
449 | 491 | | |
450 | | - | |
| 492 | + | |
451 | 493 | | |
452 | | - | |
| 494 | + | |
453 | 495 | | |
454 | | - | |
| 496 | + | |
455 | 497 | | |
456 | 498 | | |
457 | | - | |
| 499 | + | |
458 | 500 | | |
459 | 501 | | |
460 | 502 | | |
461 | 503 | | |
462 | 504 | | |
463 | 505 | | |
464 | | - | |
| 506 | + | |
465 | 507 | | |
466 | 508 | | |
467 | 509 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments