claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

MCP comment tool escapes ! in HTML comments, making markers visible

Open otavio opened this issue 9 months ago • 1 comments

Bug

When using mcp__github_comment__update_claude_comment to post a comment containing an HTML comment marker like <!-- claude-code-review -->, the ! character gets escaped to \!, resulting in <\!-- claude-code-review --> being stored in the comment body.

Since <\!-- is not valid HTML comment syntax, GitHub renders it as visible text instead of hiding it.

Reproduction

  1. Configure a workflow that uses claude-code-action with a prompt instructing Claude to include <!-- some-marker --> in a comment body via mcp__github_comment__update_claude_comment
  2. Trigger the workflow
  3. Observe the posted comment contains <\!-- some-marker --> (with \!)

Expected behavior

The HTML comment <!-- some-marker --> should be posted verbatim, so GitHub hides it as intended.

Actual behavior

The ! is escaped to \!, producing <\!-- some-marker --> which renders as visible text.

Root cause

This is likely bash history expansion escaping the ! character when the comment body passes through a shell context with double quotes. In bash, ! triggers history expansion inside double-quoted strings and gets escaped to \!.

Example

  • PR: https://github.com/shellhub-io/shellhub/pull/5868
  • Comment with the issue: https://github.com/shellhub-io/shellhub/pull/5868#issuecomment-3950939724

Environment

  • anthropics/claude-code-action@v1
  • --model claude-opus-4-6
  • Using track_progress and mcp__github_comment__update_claude_comment

otavio avatar Feb 24 '26 11:02 otavio

I've submitted a fix for this in https://github.com/anthropics/claude-code-action/pull/1028.

Root cause: The MCP comment servers (github-comment-server, github-inline-comment-server) used sanitizeContent() on outgoing comment bodies. That function is designed for input sanitization (stripping hidden content to prevent prompt injection) — but when applied to output, it also strips all HTML comments. Separately, ! in <!-- gets escaped to \! upstream, producing <\!-- which doesn't match the strip regex and passes through as visible text.

Fix: Added sanitizeOutputContent() for outgoing comment bodies that:

  • Unescapes <\!-- back to <!-- (only when a matching --> exists)
  • Preserves HTML comments in output
  • Still redacts GitHub tokens and strips invisible characters

sanitizeContent() remains unchanged for input paths.

Edge cases tested:

  1. Token inside HTML comment (<!-- ghp_xxx -->) — still redacted
  2. Double-escaped \\! — not over-unescaped, stays as \\!
  3. Mixed escaped and unescaped comments in same body — both handled correctly
  4. \! inside fenced code blocks (e.g. bash \!42) — preserved, not mangled
  5. Unclosed <\!-- with no matching --> — left escaped to prevent eating rest of page
  6. Multiline HTML comments — works
  7. Adjacent comments with no whitespace — both unescaped
  8. Prompt injection via HTML comment — output preserves (Claude's own output), input sanitizer still strips (user content)

All 666 tests pass, typecheck clean, formatting clean.

cc @OctavianGuzu @ashwin-ant

shivama205 avatar Mar 07 '26 17:03 shivama205