Fix: resolve unexpanded env vars in Slack webhook token#7
Merged
Conversation
The trigger config caches env-var-expanded values via expandEnvVars(),
but when the cache is populated before the env var is available (PM2
env mismatch, startup race), the literal string "${ELI_SLACK_BOT_TOKEN}"
is sent as the Bearer token instead of the real value. Slack returns
invalid_auth for that literal string with no further detail, which has
been silently failing for all Eli channel failure notices since April 29.
Add resolveSlackToken() that detects unexpanded ${VAR} patterns at use
time and re-expands from process.env. Also improve error logging to
include trigger name and token prefix for faster diagnosis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
The trigger config in
config.tscaches env-var-expanded values viaexpandEnvVars(). When the cache is populated before the env var is available inprocess.env(PM2 environment mismatch, startup race condition), the literal string${ELI_SLACK_BOT_TOKEN}is stored as the token value instead of the realxoxb-...token. This unexpanded string is then sent to Slack as a Bearer token, which returnsinvalid_authwith no further detail.This has been silently failing for all Eli channel failure notices since April 29 (every single Slack thread reply to Eli channels has failed).
Fix
resolveSlackToken()insrc/lib/webhooks/resolve-slack-token.tsthat detects${VAR}patterns at use time and re-expands fromprocess.envtrigger.slackBotToken || process.env.SLACK_BOT_TOKENAlert Reference
Triggered by production alert at 2026-06-25T14:20:02.065Z:
[Slack Webhook] Slack reply failed: invalid_auth thread_ts=1782396209.882939Testing
resolveSlackTokencovering: normal tokens, fallback env, unexpanded vars with/without env resolution, custom fallback keys${ELI_SLACK_BOT_TOKEN}to Slack returnsinvalid_auth, while the expanded token works