Repository navigation
fix(cli): stop boss mcp ledger printing forged rows and terminal escapes - #995
Closed
Antriksh1984 wants to merge 1 commit into
Closed
Antriksh1984 wants to merge 1 commit into
Antriksh1984 wants to merge 1 commit into
Conversation
This was referenced Sep 18, 2026
kshivang
force-pushed
the
dev
branch
3 times, most recently
from
September 22, 2026 04:42
bdcf620 to
bc9aa3b
Compare
boss mcp ledger tail/search/verify printed record fields (tool name, provider id, arguments, error snippets) raw. A record can carry a terminal escape sequence or a newline chosen by whoever supplied that field, so the CLI's own output could move the cursor, hide text or forge a line that looks like a different record. TerminalText.safe renders every non-printing character as a visible escape (\n, \t, \uXXXX) rather than passing it through, and McpLedgerCli routes every field through it before printing.
Antriksh1984
force-pushed
the
fix/mcp-ledger-terminal-injection
branch
from
September 22, 2026 09:59
2536f24 to
d15c9fa
Compare
Contributor
Author
Collaborator
|
Thanks so much for this contribution, @Antriksh1984 - the work here is genuinely appreciated, and it's clear real care went into it. This overlaps with #1001 ("fix(cli): neutralise plugin manifest text in boss plugin validate and link"), which is further along in review and will carry this change forward. To keep review attention focused, I'm closing this one in favor of #1001 - please do review and follow that PR, and you're very welcome to pick up any part of it that still needs help or take on another open issue. Your contribution credit is noted here, and anything unique in this branch that #1001 misses is still welcome as a follow-up. Thanks again for contributing to BossConsole! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
boss mcp ledger tail|search|verifyis how an operator reads the MCP audit trail. Its human output printed strings that came out of the ledger file raw:errorSnippet(McpArgumentSanitizer.sanitizeMessageonly redacts credentials, so control characters reach the file untouched),toolName,verifybreak report, therecordId, both hashes and the file names of a record that was just found to be altered.Two consequences, both in the one view an operator trusts:
2099-01-01T00:00:00Z approved_tool ALLOW/AUTO_ALLOWED ... ok hash ...) but was never written by the ledger.verifyprints for the record it reports as altered, so the report that says "this file was tampered with" was itself attacker-writable.JSON output is unaffected: its serializer already escapes control characters.
Fix
A new shared
TerminalText(safe,safeLines,safeIndented) writes anything that could act on a terminal or on the reader out as a visible escape:\n,\r,\t, or\uXXXX),It escapes rather than drops, so the operator can see that something was there. Ordinary text, including accents, CJK and emoji, is returned unchanged.
McpLedgerFormatapplies it to every ledger-derived string in the text renderings (records, break report, file names, and the read-error messages, which can quote ledger content).The helper is shared on purpose: the same class of problem exists in the other human renderings (
boss mcp listprints plugin-supplied tool names and descriptions), and I will follow up on those separately rather than widen this diff.Tests
Test-first: the three new ledger tests fail on unfixed
dev(run before the change) and pass after.tail cannot be made to print a forged record row or a terminal escape sequence- an error snippet carrying a newline, a forged row,ESC[2Jand an OSC title; asserts no control characters, no line starting with the forged timestamp, the escape stays visible, and one record still yields exactly one error line.tail neutralises control and direction-override characters in a tool nameverify neutralises control characters read back from a tampered ledger- alters a record id in the file and checks the break report.TerminalTextTestpins the helper, including that ordinary text is untouched and that a multi-line value cannot start a line that reads as a heading.McpLedgerCliTest18/18,TerminalTextTest4/4,BossMcpCliTest23/23.ktlintCheckanddetektclean.