Skip to content

fix(onboard): redact messaging tokens in session failures - #2392

Merged
jyaunches merged 3 commits into
mainfrom
fix/2336-redact-messaging-tokens-v2
Apr 24, 2026
Merged

jyaunches merged 3 commits into
mainfrom
fix/2336-redact-messaging-tokens-v2

Conversation

@jyaunches

@jyaunches jyaunches commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Rebased version of #2358, reconciled with #1970 (now on main).

What changed

Commit 1: fix(onboard) — from original #2358

Adds redaction patterns for messaging provider tokens:

  • Slack: consolidated (xox[bpas]|xapp)- pattern (covers bot, user, app-level, shared-channel)
  • Telegram: bot token patterns (bot<id>:<secret> and standalone <id>:<secret>)
  • Discord: three-part JWT-like bot tokens

Also adds messaging env-var names (SLACK_BOT_TOKEN, DISCORD_BOT_TOKEN, TELEGRAM_BOT_TOKEN) to the context-anchored KEY=value pattern in onboard-session.ts.

Updates test/secret-redaction.test.ts with behavioral tests for all new patterns including Telegram URL-path form and boundary cases.

Commit 2: refactor(security) — onboard-session import refactor

Replaces the inline regex list in redactSensitiveText() with an import from TOKEN_PREFIX_PATTERNS (secret-patterns.ts). All current and future token patterns are now automatically covered without maintaining a separate list. This is the first step toward #2381.

Reconciliation with #1970

Resolves #2336.
Supersedes #2358, #2339.
Ref: #2381

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection and redaction of sensitive tokens in logs and persisted messages, including broader Slack variants and new Telegram/Discord formats.
    • Ensured consistent redaction behavior and trimmed long persisted messages.
  • Tests

    • Expanded and reorganized tests to cover the new token patterns and redaction scenarios.
  • Chores

    • Updated tooling to use the consolidated redaction rules.

laitingsheng and others added 2 commits April 23, 2026 19:11
The onboard session writer runs every error message through
redactSensitiveText before persisting to ~/.nemoclaw/onboard-session.json,
but the regex list only covered NVIDIA, OpenAI, and GitHub (classic)
token prefixes. Slack, Discord, and Telegram tokens — the exact providers
whose failure paths print raw tokens during messaging-channel onboarding
— survived untouched, and the Telegram URL-path form
(api.telegram.org/bot<token>/getMe) is not a shape redactUrl sanitises.

Extend redactSensitiveText and the canonical secret-patterns list with
xox[bpas]-/xapp-, Telegram standalone + URL-path forms, and Discord
three-part bot tokens; also close pre-existing gaps for nvcf- and
github_pat_. Mirror the same patterns in scripts/debug.sh so shell-side
diagnostics stay in sync, and extend test/secret-redaction.test.ts with
a dedicated #2336 block covering redactSensitiveText and the Telegram
URL-path regression.

Resolves #2336.

Signed-off-by: Tinson Lai <[email protected]>
…patterns import

Replace inline regex list in redactSensitiveText() with import from
TOKEN_PREFIX_PATTERNS (secret-patterns.ts). All current and future
token patterns are now automatically covered without maintaining a
separate list.

Ref: #2381
@jyaunches jyaunches self-assigned this Apr 23, 2026
@copy-pr-bot

copy-pr-bot Bot commented Apr 23, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9b9bea81-680e-4723-a2fc-ff0023c2145b

📥 Commits

Reviewing files that changed from the base of the PR and between 16b1b0d and 46f4ed4.

📒 Files selected for processing (1)
  • src/lib/onboard-session.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/lib/onboard-session.test.ts

📝 Walkthrough

Walkthrough

Consolidates and expands secret redaction patterns: moves/adjusts sk-ant- placement, replaces multiple Slack rules with a single consolidated pattern, and adds Telegram and Discord token patterns. Shared patterns are used by shell redaction, onboarding redaction, and tests to ensure consistent masking.

Changes

Cohort / File(s) Summary
Secret Pattern Definitions
src/lib/secret-patterns.ts
Reordered and updated TOKEN_PREFIX_PATTERNS: added/moved sk-ant-, replaced multiple Slack prefix rules with a consolidated `xox...
Redaction Implementation
src/lib/onboard-session.ts, scripts/debug.sh
redactSensitiveText now iterates TOKEN_PREFIX_PATTERNS instead of in-function duplicates and expands env-var/key-context regexes to include Slack/Discord/Telegram tokens. scripts/debug.sh redact() sed rules were consolidated to match the new patterns and had duplicate sk-ant- handling removed.
Tests
test/secret-redaction.test.ts, src/lib/onboard-session.test.ts
Refactored test fixtures into LITERAL_PREFIX_TOKENS and MESSAGING_TOKENS, added tests for messaging token redaction (#2336) including Telegram-in-URL and Slack env assignments, and adjusted persisted failure-message test token length.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through logs at break of dawn,

Found tokens scattered on the lawn.
With whiskers twitch and tiny paw,
I stitched them closed — now none shall thaw.
Hooray! Secrets tucked, I nibble a carrot. 🥕

🚥 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 clearly summarizes the main change: adding redaction for messaging tokens in onboarding session failures, which is the primary objective.
Linked Issues check ✅ Passed The PR addresses all requirements from #1970 and #2336: adds Slack/Telegram/Discord token patterns to secret-patterns.ts, updates onboard-session.ts to use canonical patterns, mirrors patterns in debug.sh, and adds comprehensive tests.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issues: refactoring TOKEN_PREFIX_PATTERNS usage, consolidating Slack prefixes, adding messaging token patterns, and updating corresponding tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2336-redact-messaging-tokens-v2

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/lib/secret-patterns.ts (1)

23-25: Clarify provider scope in the prefix-order comment.

sk-ant- is Anthropic-specific; keeping the heading as only “OpenAI” is a bit misleading for future maintainers.

Proposed wording tweak
-  // OpenAI (sk-proj- before sk- so the more specific prefix matches first)
+  // OpenAI/Anthropic (specific prefixes before generic sk-)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/secret-patterns.ts` around lines 23 - 25, The comment above the regex
entries in secret-patterns.ts currently labels the section "OpenAI" but includes
an Anthropic prefix (sk-ant-); update the heading/comment to clarify provider
scope (e.g., "OpenAI and Anthropic — ensure more specific prefixes match first"
or "Provider-specific (OpenAI, Anthropic)") and keep the explanatory note about
ordering so it's clear that /sk-proj-/ and /sk-ant-/ are provider-specific
prefixes and that more specific prefixes should be listed before generic ones.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/secret-patterns.ts`:
- Around line 23-25: The comment above the regex entries in secret-patterns.ts
currently labels the section "OpenAI" but includes an Anthropic prefix
(sk-ant-); update the heading/comment to clarify provider scope (e.g., "OpenAI
and Anthropic — ensure more specific prefixes match first" or "Provider-specific
(OpenAI, Anthropic)") and keep the explanatory note about ordering so it's clear
that /sk-proj-/ and /sk-ant-/ are provider-specific prefixes and that more
specific prefixes should be listed before generic ones.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 838ac062-df56-4153-85c3-957c00b47e05

📥 Commits

Reviewing files that changed from the base of the PR and between 4482548 and 16b1b0d.

📒 Files selected for processing (4)
  • scripts/debug.sh
  • src/lib/onboard-session.ts
  • src/lib/secret-patterns.ts
  • test/secret-redaction.test.ts

…n test

The existing test used 'sk-secret-value' (12 chars after sk-) which
doesn't meet the {20,} minimum in TOKEN_PREFIX_PATTERNS. Lengthen
the test token to match real-world OpenAI key lengths.
@jyaunches
jyaunches merged commit 5e1ef51 into main Apr 24, 2026
17 checks passed
DemianHeyGen pushed a commit to DemianHeyGen/NemoClaw that referenced this pull request Apr 30, 2026
Rebased version of NVIDIA#2358, reconciled with NVIDIA#1970 (now on main).

## What changed

### Commit 1: fix(onboard) — from original NVIDIA#2358

Adds redaction patterns for messaging provider tokens:
- **Slack**: consolidated `(xox[bpas]|xapp)-` pattern (covers bot, user,
app-level, shared-channel)
- **Telegram**: bot token patterns (`bot<id>:<secret>` and standalone
`<id>:<secret>`)
- **Discord**: three-part JWT-like bot tokens

Also adds messaging env-var names (`SLACK_BOT_TOKEN`,
`DISCORD_BOT_TOKEN`, `TELEGRAM_BOT_TOKEN`) to the context-anchored
`KEY=value` pattern in `onboard-session.ts`.

Updates `test/secret-redaction.test.ts` with behavioral tests for all
new patterns including Telegram URL-path form and boundary cases.

### Commit 2: refactor(security) — onboard-session import refactor

Replaces the inline regex list in `redactSensitiveText()` with an import
from `TOKEN_PREFIX_PATTERNS` (secret-patterns.ts). All current and
future token patterns are now automatically covered without maintaining
a separate list. This is the first step toward NVIDIA#2381.

## Reconciliation with NVIDIA#1970

- Preserves all 12 provider patterns from NVIDIA#1970 (OpenAI, AWS,
HuggingFace, GitLab, Groq, PyPI, Anthropic)
- Replaces NVIDIA#1970's individual Slack patterns (`xoxb-`, `xoxp-`,
`xoxe.xoxp-`) with the consolidated `(xox[bpas]|xapp)-` class
- Fixes NVIDIA#1970's `xoxe.xoxp-` ordering bug (no longer applicable with
consolidated pattern)
- Moves `sk-ant-` before `sk-` to match `sk-proj-` ordering convention
- Keeps `sk-` at `{20,}` minimum length (not weakened to `{10,}`)

Resolves NVIDIA#2336.
Supersedes NVIDIA#2358, NVIDIA#2339.
Ref: NVIDIA#2381

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved detection and redaction of sensitive tokens in logs and
persisted messages, including broader Slack variants and new
Telegram/Discord formats.
* Ensured consistent redaction behavior and trimmed long persisted
messages.

* **Tests**
* Expanded and reorganized tests to cover the new token patterns and
redaction scenarios.

* **Chores**
  * Updated tooling to use the consolidated redaction rules.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Tinson Lai <[email protected]>
Co-authored-by: Tinson Lai <[email protected]>
Co-authored-by: Test User <[email protected]>
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
@jyaunches
jyaunches deleted the fix/2336-redact-messaging-tokens-v2 branch June 12, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Messaging Tokens (Slack/Discord/Telegram) Leaked in Onboarding Sessions

3 participants