Skip to content

fix: sanitize error messages to prevent credential leakage#11178

Closed
WhiteElephantIsNotARobot wants to merge 1 commit into
anomalyco:devfrom
WhiteElephantIsNotARobot:fix/sanitize-error-messages
Closed

fix: sanitize error messages to prevent credential leakage#11178
WhiteElephantIsNotARobot wants to merge 1 commit into
anomalyco:devfrom
WhiteElephantIsNotARobot:fix/sanitize-error-messages

Conversation

@WhiteElephantIsNotARobot

Copy link
Copy Markdown

Summary

This PR fixes a security vulnerability where sensitive environment variables and tokens were being leaked into PR comments when shell errors occurred in the GitHub Action.

Security Impact

Severity: High

The GitHub Action was posting raw stderr output from shell commands to PR comments. This could expose:

  • GITHUB_TOKEN
  • ACTIONS_ID_TOKEN_REQUEST_TOKEN
  • ACTIONS_ID_TOKEN_REQUEST_URL
  • User-provided API keys (e.g., ZHIPU_API_KEY)
  • Various GITHUB_* context variables
  • Other secrets in environment variables

Fix

Added a sanitizeErrorMessage() function that sanitizes error messages before posting them to PR comments:

  1. Redacts base64-encoded tokens: Authorization headers, x-access-token values
  2. Redacts GitHub tokens: Matches ghp_, gho_, ghr_, ghs_ prefixes
  3. Redacts common API keys: GITHUB_TOKEN, AWS credentials, OpenAI keys, etc.
  4. Redacts URLs with embedded credentials: https://token@github.com patterns
  5. Truncates suspicious long lines: Lines >200 chars with base64-like patterns

Changes

  • Modified github/index.ts to call sanitizeErrorMessage() on shell error stderr
  • Added sanitizeErrorMessage() function with comprehensive regex-based redaction

Testing

The function handles:

  • Shell errors containing environment variables
  • Git command errors with embedded tokens
  • HTTP errors with Authorization headers
  • Long base64-encoded strings

Fixes #11166

The GitHub Action was leaking sensitive environment variables and tokens
into PR comments when shell errors occurred. This fix adds a
sanitizeErrorMessage() function that:

- Redacts base64-encoded tokens (Authorization headers, x-access-token)
- Redacts GitHub tokens (ghp_, gho_, ghr_, ghs_ prefixes)
- Redacts common API keys and secrets (GITHUB_TOKEN, AWS keys, etc.)
- Redacts URLs with embedded credentials
- Truncates long lines containing base64-like patterns

This prevents exposure of credentials like GITHUB_TOKEN,
ACTIONS_ID_TOKEN_REQUEST_TOKEN, and user-provided API keys
when errors occur during shell command execution.

Fixes #11166
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@WhiteElephantIsNotARobot WhiteElephantIsNotARobot closed this by deleting the head repository Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: GitHub Action leaks environment variables into PR comments

1 participant