Skip to content

[CLAUDE ROUTINE]: Enhancement — expand redactReason coverage for modern credential formats #141

@NiveditJain

Description

@NiveditJain

Summary

Expand the redaction table in redactReason so telemetry that leaves the user's machine keeps up with today's credential formats. The current set (AWS AKIA, JWT, ghp_, generic sk-, Bearer) covers the classics; adding a handful more patterns makes the guarantee broader without a big refactor.

Where

src/relay/queue.ts:73-81

function redactReason(reason: string | null | undefined): string | null {
  if (!reason) return reason ?? null;
  return reason
    .replace(/AKIA[0-9A-Z]{16}/g, "[REDACTED-AWS-KEY]")
    .replace(/eyJ[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+/g, "[REDACTED-JWT]")
    .replace(/ghp_[A-Za-z0-9]{36,}/g, "[REDACTED-GH-TOKEN]")
    .replace(/sk-[A-Za-z0-9]{20,}/g, "[REDACTED-API-KEY]")
    .replace(/Bearer\s+[A-Za-z0-9_.=+-]+/gi, "Bearer [REDACTED]");
}

Why this helps

The reason field is derived from policy decisions and often includes shell-command text. In the common case it's boring metadata — but when it isn't, we'd rather cover more families than fewer. A quick gap analysis against common providers:

Provider / Type Example prefix Currently caught?
Anthropic sk-ant-api.. / sk-ant-admin.. Partial (dash boundary breaks greedy match)
OpenAI project sk-proj-... Partial
GitHub family gho_, ghu_, ghs_, ghr_, github_pat_ No (only ghp_)
Slack xoxb-, xoxp-, xapp- No
Stripe sk_live_, sk_test_ (underscores) No
GCP service account PEM PEM blocks No
Google OAuth client secret GOCSPX- No
npm publish token npm_ No

Expanding coverage is a quick, low-risk win: redaction is easy to unit-test with positive/negative fixtures, and the replacement table is a single file.

Proposed enhancement

const REDACTORS: Array<[RegExp, string]> = [
  // AWS
  [/AKIA[0-9A-Z]{16}/g, "[REDACTED-AWS-KEY]"],
  [/ASIA[0-9A-Z]{16}/g, "[REDACTED-AWS-STS-KEY]"],
  // Anthropic
  [/sk-ant-(api|admin)\d{2}-[A-Za-z0-9_-]{20,}/g, "[REDACTED-ANTHROPIC-KEY]"],
  // OpenAI
  [/sk-(proj-)?[A-Za-z0-9_-]{20,}/g, "[REDACTED-OPENAI-KEY]"],
  // GitHub — full family
  [/gh[pousr]_[A-Za-z0-9]{36,}/g, "[REDACTED-GH-TOKEN]"],
  [/github_pat_[A-Za-z0-9_]{60,}/g, "[REDACTED-GH-PAT]"],
  // Slack
  [/xox[baprs]-[A-Za-z0-9-]{10,}/g, "[REDACTED-SLACK-TOKEN]"],
  // Stripe
  [/(sk|pk|rk)_(live|test)_[A-Za-z0-9]{20,}/g, "[REDACTED-STRIPE-KEY]"],
  // GCP OAuth client
  [/GOCSPX-[A-Za-z0-9_-]{28}/g, "[REDACTED-GCP-OAUTH-SECRET]"],
  // npm
  [/npm_[A-Za-z0-9]{36,}/g, "[REDACTED-NPM-TOKEN]"],
  // PEM private key blocks (any label)
  [/-----BEGIN [A-Z ]*KEY-----[\s\S]+?-----END [A-Z ]*KEY-----/g, "[REDACTED-PEM-KEY]"],
  // JWT (accept 2- or 3-segment)
  [/eyJ[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+(?:\.[A-Za-z0-9_=-]+)?/g, "[REDACTED-JWT]"],
  // Header-style
  [/(Authorization|X-Api-Key|X-Auth-Token):\s*\S+/gi, "$1: [REDACTED]"],
  [/Bearer\s+[A-Za-z0-9_.=+-]+/gi, "Bearer [REDACTED]"],
];

Acceptance criteria

  • New redactors cover at minimum: Anthropic, OpenAI project, Slack, Stripe, GitHub family (+ github_pat_), GCP OAuth, npm, and PEM key blocks.
  • Unit tests with positive (should redact) and negative (must not over-redact) cases per pattern.
  • No change to call sites — redactReason remains a single-call API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions