Skip to content

[codex] Mask secrets in guardrail bash output - #190

Merged
terisuke merged 1 commit into
devfrom
codex/mask-guardrail-bash-secrets
Apr 25, 2026
Merged

[codex] Mask secrets in guardrail bash output#190
terisuke merged 1 commit into
devfrom
codex/mask-guardrail-bash-secrets

Conversation

@terisuke

Copy link
Copy Markdown

Summary

  • mask common secret formats from guardrail-managed bash output before later hooks process it
  • record a secret_masked event when redaction happens
  • add a direct hook regression test for AWS/OpenAI-style output redaction
  • widen hasCodexMcp inference so the mutable guardrail context typechecks cleanly

Validation

  • bun test test/plugin/guardrail-secret-mask.test.ts test/plugin/guardrail-review.test.ts test/plugin/guardrail-access.test.ts (from packages/opencode)
  • bun typecheck (from packages/opencode)
  • git diff --check
  • opencode --version
  • node packages/guardrails/bin/opencode-guardrails --version
  • local symlink check for ~/.config/opencode/plugins/guardrail.ts
  • push hook: bun turbo typecheck

CopilotAI review requested due to automatic review settings April 25, 2026 15:05
@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown

Hey! Your PR title [codex] Mask secrets in guardrail bash output doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@terisuke
terisuke merged commit eda3ef9 into devApr 25, 2026
5 of 12 checks passed
@terisuke
terisuke deleted the codex/mask-guardrail-bash-secrets branch April 25, 2026 15:05

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds secret redaction for guardrail-managed bash tool output so downstream hooks don’t process or persist common secret formats, and emits a secret_masked event when redaction occurs.

Changes:

  • Redact common secret patterns from bash output in the guardrail plugin and emit a secret_masked event with a count.
  • Add a regression test ensuring AWS/OpenAI-style secrets in bash output are redacted and the event is recorded.
  • Widen hasCodexMcp typing in the guardrail context to avoid overly-narrow literal inference.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

FileDescription
packages/opencode/test/plugin/guardrail-secret-mask.test.tsNew regression test validating bash-output secret masking + secret_masked event emission.
packages/guardrails/profile/plugins/guardrail.tsImplements bash-output secret masking and records a secret_masked event on redaction.
packages/guardrails/profile/plugins/guardrail-context.tsAdjusts hasCodexMcp typing to widen the inferred type for mutable context usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[/glpat-[a-zA-Z0-9-]{20,}/g, "gitlab-token"],
[/xox[bprs]-[a-zA-Z0-9-]+/g, "slack-token"],
[/npm_[a-zA-Z0-9]{36}/g, "npm-token"],
[/-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/g, "private-key"],
[/xox[bprs]-[a-zA-Z0-9-]+/g, "slack-token"],
[/npm_[a-zA-Z0-9]{36}/g, "npm-token"],
[/-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/g, "private-key"],
[/\b[A-Z_]*(?:KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL|PRIVATE)[A-Z_]*\s*=\s*["']?[A-Za-z0-9_\-+/=]{10,}["']?/gi, "env-secret"],
Comment on lines +357 to +361
const matches = output.match(pattern)
if (matches && matches.length > 0) {
output = output.replace(pattern, `[REDACTED:${label}]`)
maskedCount += matches.length
}
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@terisuke