fix(github): sanitize engine error text rendered into PR comments - #891
fix(github): sanitize engine error text rendered into PR comments#891Kiran01bm wants to merge 2 commits into
Conversation
Engine/task errors were rendered raw into PR comment blockquotes, so a multi-line or adversarial error could escape the quote, leak connection endpoints (DSNs, host:port, IPs), or flood the comment. Route every error writer through one shared sanitizer — normalize line endings, strip control/ANSI sequences, redact endpoints, clamp length — and make the task/apply error dedupe compare the sanitized form actually rendered. Raw errors stay in server logs for triage.
There was a problem hiding this comment.
Pull request overview
This PR hardens SchemaBot’s GitHub PR-comment rendering by sanitizing untrusted engine/task error text before it is emitted into Markdown blockquotes, preventing layout breakouts and reducing the risk of leaking sensitive connection endpoint details.
Changes:
- Added a shared
sanitizeCommentErrorhelper to normalize line endings, strip control characters / ANSI escapes, redact endpoint-like substrings, and clamp rendered error length. - Routed
writeErrorBlock,writeTableErrorLine, andtaskErrorAddsDetailthrough the sanitized representation and ensured multi-line errors remain within blockquotes. - Added focused unit tests covering sanitization behavior, clamping, and quoting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/webhook/templates/common.go | Introduces error sanitization + blockquote containment and applies it to error rendering/deduping paths. |
| pkg/webhook/templates/common_test.go | Adds unit tests validating sanitization, redaction, clamping, and multi-line quoting behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Redact single-label service endpoints (e.g. mysql-primary:3306) and strip Unicode format characters, including bidi overrides, from engine errors rendered in PR comments. Addresses Copilot review on #891.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
🤖 Adversarial correctness review, requested by Armand and performed by his agent. Reviewed at head f2c20e2. Verdict: the sanitization seam is correct and applied at the right boundary — approving, with a follow-up slice to cover the remaining surfaces. FindingsOther comment surfaces still render engine/apply error text with only HTML escaping, outside the new seam. Verified at head: The single-label host:port branch of the redaction regex can redact benign The sanitizer does not neutralize HTML or backticks. An error containing Action items
Verified (tried to break, couldn't)Sanitization is applied at the render boundary only — stored This review was generated by Claude Code (claude-fable-5). |
aparajon
left a comment
There was a problem hiding this comment.
🤖 Approving on Armand's behalf after the adversarial correctness review above (no blocking findings). This stamp was left by Claude Code (claude-fable-5).
Summary
Engine and task error text was rendered raw into PR comment blockquotes. A multi-line or adversarial error could escape the blockquote and break the comment layout, leak connection endpoints (DSN fragments, host:port pairs, IP addresses) into a public PR, or flood the comment with unbounded output.
What
sanitizeCommentErrorseam inpkg/webhook/templates/common.go: normalizes CRLF/CR to LF, strips ANSI escape sequences and control characters, redacts connection endpoints, trims whitespace, and clamps by rune count with a truncation marker.writeErrorBlock,writeTableErrorLine) through it, and quote continuation lines in both so multi-line errors stay inside the blockquote.taskErrorAddsDetailnow compares the sanitized representation actually rendered, so the table-level error dedupe cannot be defeated by differences sanitization erases (e.g. two dial errors differing only in the redacted endpoint).Why
Follows up the apply-comment UX stream: now that failed-table errors are surfaced in the comment, every rendered error must be safe for a public surface. Genuine engine errors (e.g. a Spirit preflight check reason) render intact; only infrastructure detail is redacted. The raw error remains in server logs with the apply identifiers, so triage loses nothing.