Skip to content

gha_echo/sanitize_gha_log_output doesn't strip ANSI escape or other control characters #472

Description

@ggallen

What happens

_sanitize_workflow_value (in scripts/lib/post-failure-report.lib.sh), the function underlying gha_echo/sanitize_gha_log_output/sanitize_comment_workflow_commands, strips literal :: and percent-encoded %0A/%0a/%0D/%0d sequences, but does not strip ANSI escape sequences (\x1b[...) or other control characters:

_sanitize_workflow_value() {
  local value="$1"
  value="${value//::/}"
  value="${value//%0A/}"
  value="${value//%0a/}"
  value="${value//%0D/}"
  value="${value//%0d/}"
  printf '%s' "${value}"
}

This function is the shared sanitization primitive for every gha_echo call across the codebase (post-code.sh, post-fix.sh, post-review.sh, post-retro.sh, pr-assignee.lib.sh, relabel-retrigger.lib.sh, etc.) — any of these that echo externally-sourced text (API error bodies, review content, etc.) through gha_echo inherit this gap.

What should happen

_sanitize_workflow_value (or a variant used specifically where externally-sourced text is involved) should also strip ANSI/CSI escape sequences and other non-printable control characters, consistent with defense-in-depth for GitHub Actions workflow-command log injection.

Context

Flagged during review of #469 (scripts/lib/relabel-retrigger.lib.sh's retrigger_via_label, which passes gh CLI stderr output through gha_echo). Not fixed as part of that PR since the gap is in shared infrastructure used by many other call sites, not something introduced there — a local, one-off fix in a single consumer would leave every other gha_echo caller with the same gap and create inconsistent sanitization behavior across the codebase. In practice, gh CLI disables ANSI color output when stderr isn't a TTY (which is the case for all these redirected-to-file/variable call sites), so the practical exposure is low, but the sanitizer's documented contract (stripping workflow-command-injection vectors) doesn't fully match its implementation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions