Skip to content

[WRONG BRANCH] fix(oauth): redact secrets in structured OAuth event logs - #185

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-oauth-logger-vulnerability
Draft

[WRONG BRANCH] fix(oauth): redact secrets in structured OAuth event logs#185
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-oauth-logger-vulnerability

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The existing OAuth event logger used an exact-key denylist and stringified values, which could leak common snake_case token fields (e.g. access_token, refresh_token, id_token, client_secret) or token-shaped values stored under benign keys.

Description

  • Apply the repository's shared secret redactor by importing and calling redactSecretString on the assembled log line before calling console.info in src/oauth/log.ts.
  • Broaden the denylist to suppress code_verifier alongside existing token/secret names and rely on the existing normalization to catch camelCase/snake_case/kebab-case field names.
  • Ensure values are not emitted raw by running the full joined parts string through redactSecretString instead of writing parts.join(" ") directly.
  • Add regression coverage in tests/oauth-log.test.ts to assert suppression of code_verifier and that token-shaped values (Bearer tokens, sk- keys) embedded under otherwise safe keys are redacted.

Testing

  • Ran bun test tests/oauth-log.test.ts, which passed (3 tests, 0 failures).
  • Ran bun run typecheck, which passed with no type errors reported.
  • Ran bun run privacy:scan, which passed and did not flag new privacy leaks.
  • Ran the full suite with bun run test; the OAuth-specific changes are green but the full test run surfaced unrelated environment-sensitive failures in other tests (tests/codex-sync-api.test.ts and tests/cli-help.test.ts) that are not caused by this change.

Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Improved OAuth log redaction to prevent sensitive token-like values from appearing in logs.
    • Added protection for code_verifier fields.
    • Ensured secrets are redacted even when recorded under otherwise safe field names.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

⚠️ Wrong target branch

This pull request currently targets main, but pull requests must target one of dev.

@luvs01 Please retarget this PR to dev. All contributions go to dev; main receives only release promotions. See our Contributing guide for details. Thanks! 🙏

Its title has been prefixed with [WRONG BRANCH].

This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again.

@github-actions github-actions Bot changed the title fix(oauth): redact secrets in structured OAuth event logs [WRONG BRANCH] fix(oauth): redact secrets in structured OAuth event logs Aug 9, 2026
@github-actions
github-actions Bot marked this pull request as draft August 9, 2026 05:08
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

OAuth logging now redacts assembled messages before output. The forbidden OAuth field list includes code_verifier. Tests cover forbidden keys and token-shaped values under safe field names.

Changes

OAuth logging sanitization

Layer / File(s) Summary
OAuth log redaction and validation
src/oauth/log.ts, tests/oauth-log.test.ts
redactSecretString sanitizes OAuth log messages before console.info. code_verifier is added to forbidden fields. Tests verify forbidden-key handling and redaction of Bearer-style and secret-key-shaped values while preserving safe fields and status.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: wibias, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: redacting secrets in structured OAuth event logs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/propose-fix-for-oauth-logger-vulnerability

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/oauth/log.ts`:
- Line 49: Update the OAuth diagnostic sanitization around redactSecretString
and isForbiddenFieldKey to redact code_verifier= values and reject normalized
field keys ending in _code_verifier, preventing PKCE verifiers from reaching
console.info. Add regression coverage for both direct verifier redaction and
forbidden suffixed keys in tests/oauth-log.test.ts.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cedef752-387c-4a1f-9ba7-e5742157054e

📥 Commits

Reviewing files that changed from the base of the PR and between 8a9c0ef and a9c5afe.

📒 Files selected for processing (2)
  • src/oauth/log.ts
  • tests/oauth-log.test.ts

Comment thread src/oauth/log.ts
parts.push(`${key}=${String(value)}`);
}
console.info(parts.join(" "));
console.info(redactSecretString(parts.join(" ")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 12 'SECRET_VALUE_PATTERNS|maskCredentialHeaders|redactSecretString' src/lib/redact.ts
rg -n -C 4 'logOAuthEvent|code_verifier|codeVerifier|code-verifier|oauth_code_verifier|oauthCodeVerifier' src tests

Repository: luvs01/opencodex

Length of output: 17129


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- src/oauth/log.ts ---'
cat -n src/oauth/log.ts | sed -n '1,90p'

printf '%s\n' '--- oauth log tests ---'
cat -n tests/oauth-log.test.ts | sed -n '1,140p'

printf '%s\n' '--- all logOAuthEvent call sites ---'
rg -n -C 3 'logOAuthEvent\s*\(' src tests

Repository: luvs01/opencodex

Length of output: 9604


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- redaction framing rules ---'
cat -n src/lib/redact.ts | sed -n '240,445p'

printf '%s\n' '--- redaction tests for OAuth and verifier-shaped values ---'
rg -n -C 5 'redactSecretString|code_verifier|code-verifier|verifier|Bearer|api[_-]?key' tests src/lib/redact.ts

printf '%s\n' '--- standalone PKCE-pattern probe ---'
node - <<'JS'
const verifier = "A".repeat(43) + "._~-9";
const samples = [
  `diagnostic: code_verifier=${verifier}`,
  `diagnostic=code_verifier=${verifier}`,
  `oauth_code_verifier=${verifier}`,
  `code-verifier=${verifier}`,
];

const patterns = [
  [/\b(Bearer)([^\S\r\n]+)[A-Za-z0-9._~+/=-]{8,}\b/gi, "bearer"],
  [/\b(sk-[A-Za-z0-9][A-Za-z0-9._-]{6,})\b/g, "sk"],
  [/\b(gh[pousr]_[A-Za-z0-9_]{8,}|github_pat_[A-Za-z0-9_]{20,})\b/g, "github"],
  [/\btid=[A-Za-z0-9-]+(?:;[A-Za-z0-9_.-]+=[^;\s"']*)+(?::[A-Za-z0-9+/=_-]+)?/g, "copilot"],
  [/\b((?:api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|client[_-]?secret|refreshToken|accessToken|clientSecret|apiKey)=)([^&\s"',;]+)/gi, "key-value"],
];

for (const sample of samples) {
  const matches = patterns
    .filter(([pattern]) => pattern.test(sample))
    .map(([, name]) => name);
  for (const [pattern] of patterns) pattern.lastIndex = 0;
  console.log(JSON.stringify({ sample, matches }));
}
JS

Repository: luvs01/opencodex

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

cat -n src/lib/redact.ts | sed -n '240,445p'

printf '%s\n' '--- standalone probe output ---'
node - <<'JS'
const verifier = "A".repeat(43) + "._~-9";
const samples = [
  `diagnostic: code_verifier=${verifier}`,
  `diagnostic=code_verifier=${verifier}`,
  `oauth_code_verifier=${verifier}`,
  `code-verifier=${verifier}`,
];

const patterns = [
  [/\b(Bearer)([^\S\r\n]+)[A-Za-z0-9._~+/=-]{8,}\b/gi, "bearer"],
  [/\b(sk-[A-Za-z0-9][A-Za-z0-9._-]{6,})\b/g, "sk"],
  [/\b(gh[pousr]_[A-Za-z0-9_]{8,}|github_pat_[A-Za-z0-9_]{20,})\b/g, "github"],
  [/\btid=[A-Za-z0-9-]+(?:;[A-Za-z0-9_.-]+=[^;\s"']*)+(?::[A-Za-z0-9+/=_-]+)?/g, "copilot"],
  [/\b((?:api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|client[_-]?secret|refreshToken|accessToken|clientSecret|apiKey)=)([^&\s"',;]+)/gi, "key-value"],
];

for (const sample of samples) {
  const matches = [];
  for (const [pattern, name] of patterns) {
    pattern.lastIndex = 0;
    if (pattern.test(sample)) matches.push(name);
  }
  console.log(JSON.stringify({ sample, matches }));
}
JS

Repository: luvs01/opencodex

Length of output: 12325


Redact PKCE verifiers embedded in OAuth diagnostics.

redactSecretString does not match code_verifier= values, and isForbiddenFieldKey does not reject keys such as oauth_code_verifier. A PKCE verifier can therefore reach console.info through an otherwise safe field. Add a verifier-specific redaction rule and reject normalized keys ending in _code_verifier. Add regression tests for both cases in tests/oauth-log.test.ts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/oauth/log.ts` at line 49, Update the OAuth diagnostic sanitization around
redactSecretString and isForbiddenFieldKey to redact code_verifier= values and
reject normalized field keys ending in _code_verifier, preventing PKCE verifiers
from reaching console.info. Add regression coverage for both direct verifier
redaction and forbidden suffixed keys in tests/oauth-log.test.ts.

Source: Path instructions

Sign up for free to 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.

1 participant