Skip to content

fix(discord): prevent REST failures from exposing credentials - #116805

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
Leon-SK668:alix/oc-t24-05-discord-error-redaction
Jul 31, 2026
Merged

vincentkoc merged 3 commits into
openclaw:mainfrom
Leon-SK668:alix/oc-t24-05-discord-error-redaction

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Discord REST failures could retain credentials reflected by Discord or an intermediary in error messages, structured response bodies, rate-limit headers, and scheduler diagnostic keys. Those values flow through the shared REST client used by normal sends, interaction webhooks, command deployment, and voice-message requests.

Why This Change Was Made

The repair is owned at the shared Discord REST boundary:

  • DiscordError sanitizes bounded text and structured diagnostics before retaining message, rawBody, or rawError.
  • Discord error codes and retry metadata are still derived from the original parsed response, so classification and retry behavior do not depend on diagnostic truncation.
  • Rate-limit bucket identifiers are stored as stable SHA-256 prefixes, while scope accepts only Discord's documented user, global, or shared values.
  • Webhook-token route segments are hashed before scheduler identities or metrics retain them. The actual request URL is unchanged.

This is the best owner boundary because every REST failure consumer receives the same sanitized object and scheduler grouping stays deterministic without caller-specific cleanup.

Discord contract: https://docs.discord.com/developers/topics/rate-limits

User Impact

Operators can inspect Discord REST failures and scheduler metrics without reflected bot or webhook credentials being retained. Successful requests, Discord error classification, retry timing, and route-to-bucket grouping remain unchanged.

Evidence

Production-path proof

The focused test starts a real loopback HTTP server and sends a synthetic credential through production RequestClient. The server reflects it through:

  • JSON values and keys
  • nested objects and validation arrays
  • numeric values under sensitive ancestors
  • URLs and plain text
  • X-RateLimit-Bucket and X-RateLimit-Scope
  • a credential-bearing /webhooks/{id}/{token} route

Assertions prove the credential is absent from retained errors and scheduler metrics, Discord codes and retry metadata remain available, repeated webhook requests retain stable bucket grouping, and successful responses are unchanged.

Final head

  • Exact head: 292f0a5a6f519f1b94cb8ba1f73ee4b6e0d84128
  • Contributor commits by Alix-007 were rebased byte-for-byte onto 383363e3623374db34c2b855f52f244caa688998.
  • Maintainer commit 292f0a5a6f51 closes the sibling webhook scheduler-key leak found during deep review.
  • Current-main audit at 849dde12d0d0b16792ab5e8032bb37dab1afcf01: no touched-path drift since the branch base; clean merge tree a21c179399d2d4c9e0611c91f2d5c5f6b997e583.

Validation

  • 7 focused Discord suites: 101 tests passed.
  • Focused unrelated CI-flake reproduction: 1 test passed in 2.9 seconds.
  • Extension production typecheck: passed.
  • Extension test typecheck: passed.
  • Typed changed-file oxlint: passed.
  • oxfmt --check, plugin boundary, max-lines ratchet, conflict-marker, import-cycle, diff, and secret scans: passed.
  • Exact-head Codex autoreview: clean, patch correct (0.98), no accepted/actionable findings.
  • Exact-head ClawSweeper: 5/6 diamond, proof sufficient, no findings.
  • Hosted exact-head CI: 95/95 latest checks terminal-success. Targeted reruns cleared an infrastructure-terminated lint job and one unrelated runner-load process-test flake.

Blacksmith Testbox's delegated command channel hung before producing test output on two fresh leases. Per repository fallback policy, the full focused proof ran in the trusted checkout; hosted exact-head CI is the independent remote gate.

Not tested: a real bot credential against Discord's public service. The proof deliberately uses a synthetic credential through the production client so no live secret is exposed.

AI Assistance

This change was developed with AI assistance. The author and maintainer reviewed the code, tests, and evidence and remain responsible for the contribution.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: M labels Jul 31, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 6:28 PM ET / 22:28 UTC.

ClawSweeper review

What this changes

The PR sanitizes Discord REST failure diagnostics and replaces retained rate-limit and webhook-token identifiers with stable hashes so reflected credentials are not exposed without changing retry grouping.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The patch is a coherent repair for a current Discord credential-retention path and the final maintainer amendment closes the remaining webhook scheduler-key leak. No actionable correctness finding surfaced; keep this PR open while a maintainer refreshes the interrupted exact-head lint/check set before merge.

Priority: P1
Reviewed head: 292f0a5a6f519f1b94cb8ba1f73ee4b6e0d84128

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch has strong owner-boundary design, focused real-path proof, a reviewed final amendment, and no actionable correctness finding; the remaining blocker is refresh of the exact-head GitHub gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): A production-RequestClient loopback proof uses a synthetic Authorization credential and verifies sanitized retained errors; the final-head member review reports focused Discord suites passing after the scheduler-key amendment.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): A production-RequestClient loopback proof uses a synthetic Authorization credential and verifies sanitized retained errors; the final-head member review reports focused Discord suites passing after the scheduler-key amendment.
Evidence reviewed 6 items Current-main exposure path: Current main stores an unmodified failed-response body in both raw diagnostic fields, so a reflected credential can remain attached to a Discord error object.
Shared-owner repair: The final PR head sanitizes the user-visible message and retained raw body at DiscordError construction while preserving numeric Discord classification from the original parsed response.
Scheduler and webhook identity parity: The final head hashes the webhook-token route segment and uses the same hashed rate-limit bucket reader in both scheduler paths, keeping route-to-bucket equality deterministic without retaining raw identifiers.
Findings None None.
Security None None.

How this fits together

Discord’s REST client turns unsuccessful API responses into error objects used by normal sends, webhooks, voice messages, and rate-limit scheduling. This patch changes the boundary where response diagnostics and route identities are retained before they reach retry state or operator-visible errors.

flowchart LR
  A[Discord REST response] --> B[Discord request client]
  B --> C[Error and rate-limit parsing]
  C --> D[Credential redaction boundary]
  D --> E[Sanitized error diagnostics]
  D --> F[Stable hashed bucket identity]
  F --> G[Rate-limit scheduler]
  G --> H[Retry grouping]
Loading

Before merge

  • Resolve merge risk (P1) - The PR is mergeable but behind current main, and the exact final-head check set is not yet fully green: check-lint was interrupted by a hosted-runner shutdown while several checks remain in progress. A maintainer should refresh the exact-head gates before landing.
  • Resolve merge risk (P1) - Because this changes the identifiers used by Discord rate-limit scheduling, merge should retain the focused proof that webhook routes sharing a Discord major parameter continue to share a bucket after token hashing.
  • Complete next step (P2) - No mechanical repair is indicated; a maintainer needs to refresh the interrupted exact-head checks and decide merge readiness once GitHub reports their final state.
Agent review details

Security

None.

PR surface

Source +181, Tests +281. Total +462 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 191 10 +181
Tests 1 281 0 +281
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 472 10 +462

Review metrics

None.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/discord/src/internal/rest-errors.redaction.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh the final-head gate (recommended)
    Rerun the interrupted lint job and wait for the remaining exact-head checks before merging the credential-boundary and retry-grouping change.
  2. Pause for a fresh base review
    If the refreshed run exposes a real failure or the rebase changes the Discord REST surface, pause this branch and review the resulting head rather than accepting the current CI uncertainty.

Technical review

Best possible solution:

Keep one shared redaction boundary for retained Discord REST failures, retain stable hashed scheduler identifiers for bucket correlation, and merge only after the refreshed exact-head checks confirm the final behavior.

Do we have a high-confidence way to reproduce the issue?

Yes—source inspection shows current main retains the parsed failed response as rawBody and rawError; the supplied focused loopback test sends a synthetic Authorization value through the production RequestClient and verifies it is absent from the retained error data.

Is this the best way to solve the issue?

Yes—the shared DiscordError construction boundary is the narrowest maintainable owner for sanitizing all REST failure consumers, and the paired scheduler-route hashing addresses the adjacent retained webhook-token identity without changing successful requests.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5620ea7c57d6.

Labels

Label justifications:

  • P1: A normal Discord REST failure can retain credentials reflected by an upstream service or intermediary, affecting active channel operations and operator diagnostics.
  • merge-risk: 🚨 message-delivery: The patch changes webhook route and rate-limit bucket identities used to group and schedule Discord retries.
  • merge-risk: 🚨 security-boundary: The patch changes the boundary that stores and exposes failed-response diagnostics containing potentially reflected credentials.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): A production-RequestClient loopback proof uses a synthetic Authorization credential and verifies sanitized retained errors; the final-head member review reports focused Discord suites passing after the scheduler-key amendment.
  • proof: sufficient: Contributor real behavior proof is sufficient. A production-RequestClient loopback proof uses a synthetic Authorization credential and verifies sanitized retained errors; the final-head member review reports focused Discord suites passing after the scheduler-key amendment.

Evidence

What I checked:

  • Current-main exposure path: Current main stores an unmodified failed-response body in both raw diagnostic fields, so a reflected credential can remain attached to a Discord error object. (extensions/discord/src/internal/rest-errors.ts:60, 5620ea7c57d6)
  • Shared-owner repair: The final PR head sanitizes the user-visible message and retained raw body at DiscordError construction while preserving numeric Discord classification from the original parsed response. (extensions/discord/src/internal/rest-errors.ts:213, 292f0a5a6f51)
  • Scheduler and webhook identity parity: The final head hashes the webhook-token route segment and uses the same hashed rate-limit bucket reader in both scheduler paths, keeping route-to-bucket equality deterministic without retaining raw identifiers. (extensions/discord/src/internal/rest-scheduler.ts:311, 292f0a5a6f51)
  • Redaction helper contract: The imported plugin-SDK helper performs registered-secret and pattern redaction before sensitive structured-key masking, while the identifier helper emits stable SHA-256 prefixes for non-empty values. (src/logging/redact.ts:1161, 5620ea7c57d6)
  • Final-head proof and review: The member review for the final head reports seven focused Discord suites passing and confirms the added scheduler redaction preserves Discord major-parameter grouping; the PR also has a sufficient-proof label and the supplied loopback proof exercises the production RequestClient with a synthetic Authorization credential. (292f0a5a6f51)
  • Feature-history provenance: Current-main blame attributes the pre-repair Discord error owner path to the existing area contributor, while the final scheduler-key repair is a separate commit by the reviewing member. (extensions/discord/src/internal/rest-errors.ts:56, f0170ca238)

Likely related people:

  • vincentkoc: Reviewed the completed change, identified the adjacent webhook-token scheduler exposure, and authored the final repair commit. (role: reviewer and final-patch contributor; confidence: high; commits: 292f0a5a6f51; files: extensions/discord/src/internal/rest-routes.ts, extensions/discord/src/internal/rest-scheduler.ts)
  • WhatsSkiLL: Current-main blame attributes the existing DiscordError and RateLimitError retention behavior to this area’s present source history; shallow history prevents a fuller ownership trail. (role: current error-path contributor; confidence: medium; commits: f0170ca238; files: extensions/discord/src/internal/rest-errors.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-07-31T11:49:47.695Z sha 37c2ae8618c60c7cd8940b4ee2258ccccaca873e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T15:55:31.843Z sha 0cc4e400157dc2a8352819587a1a3d6ab9333ec1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T16:00:18.303Z sha 0cc4e400157dc2a8352819587a1a3d6ab9333ec1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T16:27:47.770Z sha 0cc4e400157dc2a8352819587a1a3d6ab9333ec1 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T16:44:15.151Z sha 0cc4e400157dc2a8352819587a1a3d6ab9333ec1 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T22:20:58.378Z sha 292f0a5 :: needs maintainer review before merge. :: none

@Leon-SK668

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 31, 2026
@Leon-SK668 Leon-SK668 closed this Jul 31, 2026
@Leon-SK668 Leon-SK668 reopened this Jul 31, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 31, 2026
@Leon-SK668

Copy link
Copy Markdown
Contributor Author

Author-side follow-up is complete on exact head 0cc4e400157dc2a8352819587a1a3d6ab9333ec1.

ClawSweeper now marks the proof sufficient, rates the PR platinum, and reports no actionable finding. Fresh CI run 30646600130 passed every job except check-lint and its downstream ci-gate. The lint log contains no diagnostic: the hosted runner received a shutdown signal while oxlint was running and exited 143. This is the second current-head run with the same infrastructure termination; the full implementation head previously passed check-lint, and the only subsequent source change removes an unused export.

Contributor credentials cannot invoke the upstream rerun API. Maintainer action requested: rerun the failed jobs on run 30646600130. No further author-side code or proof change is indicated.

@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@vincentkoc
vincentkoc force-pushed the alix/oc-t24-05-discord-error-redaction branch from 0cc4e40 to 292f0a5 Compare July 31, 2026 22:14
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer review update for exact head 292f0a5a6f519f1b94cb8ba1f73ee4b6e0d84128:

  • Accepted the shared hashed X-RateLimit-Bucket representation. It preserves deterministic Discord bucket grouping without retaining attacker-controlled raw header values.
  • Deep sibling review found scheduler metric keys still retained raw webhook tokens from /webhooks/{id}/{token} routes, including rate-limited buckets. The added maintainer commit hashes only that credential segment while preserving Discord's documented webhook_id + webhook_token major-parameter grouping.
  • Focused proof: 7 Discord suites, 101 tests passed; extension production and test typechecks passed; typed lint, formatting, plugin boundary, max-lines, conflict-marker, import-cycle, diff, and secret scans passed.
  • Blacksmith Testbox command execution hung before test output on two fresh leases; per repository fallback policy, the full focused proof ran in the trusted checkout. Hosted exact-head CI is the independent remote gate.

Discord contract: https://docs.discord.com/developers/topics/rate-limits

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Jul 31, 2026
@clawsweeper clawsweeper Bot added the rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. label Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Final maintainer closeout for exact head 292f0a5a6f519f1b94cb8ba1f73ee4b6e0d84128:

Ready for the final maintainer merge decision.

@vincentkoc
vincentkoc merged commit b832287 into openclaw:main Jul 31, 2026
251 of 258 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants