fix(discord): resolve env-backed SecretRefs in startup token path#76383
fix(discord): resolve env-backed SecretRefs in startup token path#76383neeravmakwana wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Align resolveDiscordToken with Telegram: inspect SecretRefs, resolve env:provider:id via secrets.providers/allowlists, keep strict unresolved non-env refs. Fixes openclaw#76371. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. Source inspection of current main shows Next step before merge Security Review detailsBest possible solution: Land the focused Discord plugin fix after normal CI, while keeping broader runtime-snapshot and non-env SecretRef work tracked separately. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection of current main shows Is this the best way to solve the issue? Yes. The proposed change is a narrow Discord-owned repair aligned with Telegram's env SecretRef behavior and preserves strict handling for non-env refs, leaving the broader runtime-snapshot problem to separate issues. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 31161abd40fd. |
|
Hi @neeravmakwana — overlap heads-up: I opened #76385 4 minutes after this one for the same bug (originally filed as #76371 from a real Your Telegram-style approach (resolve env SecretRefs by their own Closing #76385 in favor of this one and adding a |
|
Thanks @neeravmakwana for the patch. The merged fix in #76449 landed the broader Discord solution by resolving external channel secret contracts generically, so the startup token path is covered without a Discord-only workaround. Closing this PR as superseded by the merged fix. |
Problem
Discord channel startup failed when
channels.discord.tokenused an env-backedSecretRef:normalizeDiscordTokencallednormalizeResolvedSecretInputStringon raw config and threw (env:default:DISCORD_BOT_TOKENunresolved) before Gateway secrets/runtime resolution ran. Telegram already handled this pattern viainspect+ env lookup.Root cause
resolveDiscordTokennormalized account/channel tokens through the strict secret-input helper, which treats unresolved refs as fatal instead of resolvingsource: "env"refs againstsecrets.providers, allowlists, andprocess.env(same chain as Telegram’s bot token resolver).Fix
resolveSecretInputString(..., mode: "inspect"), then follow envSecretRefs through the same provider/allowlist/default-alias rules as Telegram (resolveDefaultSecretProviderAlias, allowlist errors, non-env provider source mismatch throws).DISCORD_BOT_TOKENwhen a different ref id was configured.Why this is safe
Behavior is aligned with
extensions/telegram/src/token.tsfor env-backed refs: same validation surface, same failure modes for misconfigured providers, and strict resolution still applies to non-env refs via the existingmode: "strict"path.Security / runtime controls (unchanged)
SecretRefs still resolve through strict mode (throw), not silently dropped.Tests run
pnpm exec vitest run extensions/discord/src/token.test.tspnpm test:extension discordpnpm check:changedFollow-ups (out of scope)
Fixes #76371
pnpm test:extension discord+ targeted token tests +pnpm check:changed