Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5f44cde
fix(channels): pre-validate Slack auth to prevent gateway crash (#2340)
ericksoa Apr 23, 2026
bd61cc1
fix(channels): only disable Slack on definitive auth errors
ericksoa Apr 23, 2026
34009b3
test(e2e): add Slack auth pre-validation to messaging-providers test
ericksoa Apr 23, 2026
70ce88e
fix(e2e): address review feedback on Slack auth e2e tests
ericksoa Apr 23, 2026
2f7ac9b
fix(channels): detect unresolved Slack placeholders in config
ericksoa Apr 23, 2026
9cb663e
fix(e2e): collect entrypoint logs before Slack assertions
ericksoa Apr 23, 2026
3b2e325
test(e2e): check Slack config in Phase 3 while container is alive
ericksoa Apr 23, 2026
e335a1b
fix(channels): rewrite placeholder check as grep, add trace logging
ericksoa Apr 23, 2026
21bd3c0
fix(channels): replace config-write approach with NODE_OPTIONS preload
ericksoa Apr 23, 2026
16bd748
fix(channels): catch both sync and async Slack errors in guard
ericksoa Apr 23, 2026
169564b
test(e2e): read gateway.log via openshell exec (root) not SSH (sandbox)
ericksoa Apr 23, 2026
4f12cab
test(e2e): add guard installation diagnostics to Phase 3
ericksoa Apr 23, 2026
e378e72
fix(channels): pre-validate Slack auth to prevent gateway crash (#2340)
ericksoa Apr 23, 2026
c145798
Merge branch 'main' into fix/slack-auth-crash-2340
ericksoa Apr 23, 2026
bdf4f25
fix(channels): replace pre-validation with runtime guard (#2340)
ericksoa Apr 23, 2026
70f2206
Merge branch 'main' into fix/slack-auth-crash-2340
ericksoa Apr 23, 2026
cd8ca6b
fix(channels): move guard install after configure_messaging_channels
ericksoa Apr 23, 2026
0dc68d6
fix(channels): degrade gracefully on non-root Slack token override
ericksoa Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,141 @@ PYSLACK
printf '[channels] Config hash recomputed after Slack token override\n' >&2
}

# ── Slack auth pre-validation ────────────────────────────────────
# Prevents the gateway from crashing when a Slack channel is configured
# with tokens that will fail at connect time (unresolved placeholders or
# revoked/expired credentials). Two checks run in order:
#
# Check 1 — grep the config for openshell:resolve:env:SLACK_ placeholders.
# In the OpenShell provider model the real token lives in the L7 proxy,
# not the container env, so apply_slack_token_override cannot resolve it.
# Bolt validates token format in-process (botToken must start with xoxb-,
# appToken with xapp-); an unresolved placeholder crashes the gateway.
#
# Check 2 — if the real token IS in the container env (xoxb- prefix),
# call Slack auth.test to verify it before the gateway starts. Only
# definitive auth errors disable the channel; transient/network errors
# leave it enabled so the gateway can retry.
#
# Ref: https://github.com/NVIDIA/NemoClaw/issues/2340

validate_slack_auth() {
local config_file="/sandbox/.openclaw/openclaw.json"
local hash_file="/sandbox/.openclaw/.config-hash"

printf '[channels] validate_slack_auth: starting (SLACK_BOT_TOKEN=%s)\n' \
"${SLACK_BOT_TOKEN:+set:${SLACK_BOT_TOKEN:0:5}...}" >&2

# SECURITY: Refuse to write through symlinks to prevent symlink-following attacks.
if [ -L "$config_file" ] || [ -L "$hash_file" ]; then
printf '[SECURITY] Refusing Slack auth validation — config or hash path is a symlink\n' >&2
return 1
fi

# ── Check 1: unresolved placeholders (grep, no python3) ──────
# A simple grep is more robust than a python3 heredoc subshell and
# cannot fail silently. If any Slack placeholder token survives in the
# config after apply_slack_token_override, the channel must be disabled.
if grep -q '"openshell:resolve:env:SLACK_' "$config_file" 2>/dev/null; then
printf '[channels] [slack][default] config contains unresolved Slack placeholder — Bolt will reject token format; channel disabled\n' >&2

python3 - "$config_file" <<'PYSLACKDISABLE'
import json, sys
config_file = sys.argv[1]
with open(config_file) as f:
cfg = json.load(f)
slack = cfg.get("channels", {}).get("slack", {})
for acct in slack.get("accounts", {}).values():
if isinstance(acct, dict):
acct["enabled"] = False
with open(config_file, "w") as f:
json.dump(cfg, f, indent=2)
PYSLACKDISABLE

(cd /sandbox/.openclaw && sha256sum openclaw.json >"$hash_file")
printf '[channels] Config hash recomputed after disabling Slack channel\n' >&2
return 0
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
fi
printf '[channels] validate_slack_auth: no Slack placeholders in config\n' >&2

# ── Check 2: validate resolved token via Slack API ────────────
[ -n "${SLACK_BOT_TOKEN:-}" ] || return 0
case "${SLACK_BOT_TOKEN}" in
xoxb-*) ;;
*)
printf '[channels] validate_slack_auth: SLACK_BOT_TOKEN prefix is not xoxb- — skipping API check\n' >&2
return 0
;;
esac

printf '[channels] Validating Slack bot token against auth.test...\n' >&2

local auth_result
auth_result=$(
SLACK_BOT_TOKEN="$SLACK_BOT_TOKEN" python3 <<'PYAUTHTEST'
import json, os, sys, urllib.request
token = os.environ["SLACK_BOT_TOKEN"]
try:
req = urllib.request.Request(
"https://slack.com/api/auth.test",
headers={"Authorization": "Bearer " + token,
"Content-Type": "application/x-www-form-urlencoded"},
data=b"",
)
with urllib.request.urlopen(req, timeout=10) as resp:
data = json.loads(resp.read())
if data.get("ok"):
print("ok")
else:
print("error:" + data.get("error", "unknown"))
except Exception as e:
print("network_error:" + str(e)[:200])
PYAUTHTEST
) || auth_result="network_error:python3_failed"

# Definitive auth failures that warrant disabling the channel. Transient
# or service-side errors (ratelimited, request_timeout, service_unavailable,
# internal_error, fatal_error) should NOT disable — the gateway may succeed
# if the issue resolves by the time it connects.
# Ref: https://docs.slack.dev/reference/methods/auth.test
local _fatal_auth_errors="account_inactive invalid_auth not_authed token_expired token_revoked missing_scope not_allowed_token_type"

case "$auth_result" in
ok)
printf '[channels] Slack bot token validated successfully\n' >&2
;;
error:*)
local slack_error="${auth_result#error:}"

# shellcheck disable=SC2076 # we want literal match, not pattern
if [[ " $_fatal_auth_errors " =~ " $slack_error " ]]; then
printf '[channels] [slack][default] provider failed to start: %s — channel disabled\n' "$slack_error" >&2

python3 - "$config_file" <<'PYSLACKDISABLE2'
import json, sys
config_file = sys.argv[1]
with open(config_file) as f:
cfg = json.load(f)
slack = cfg.get("channels", {}).get("slack", {})
for acct in slack.get("accounts", {}).values():
if isinstance(acct, dict):
acct["enabled"] = False
with open(config_file, "w") as f:
json.dump(cfg, f, indent=2)
PYSLACKDISABLE2

(cd /sandbox/.openclaw && sha256sum openclaw.json >"$hash_file")
printf '[channels] Config hash recomputed after disabling Slack channel\n' >&2
else
printf '[channels] Slack auth.test returned transient error: %s — channel left enabled\n' "$slack_error" >&2
fi
;;
network_error:*)
printf '[channels] Could not reach Slack API for token validation (%s) — channel left enabled\n' "${auth_result#network_error:}" >&2
;;
esac
}

_read_gateway_token() {
python3 - <<'PYTOKEN'
import json
Expand Down Expand Up @@ -996,6 +1131,7 @@ if [ "$(id -u)" -ne 0 ]; then
apply_model_override
apply_cors_override
apply_slack_token_override
validate_slack_auth
export_gateway_token
install_configure_guard
configure_messaging_channels
Expand Down Expand Up @@ -1111,6 +1247,7 @@ verify_config_integrity /sandbox/.openclaw
apply_model_override
apply_cors_override
apply_slack_token_override
validate_slack_auth
export_gateway_token
install_configure_guard

Expand Down
8 changes: 8 additions & 0 deletions test/e2e/brev-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
* BREV_MIN_DISK — Minimum disk size in GB (default: 50)
* TELEGRAM_BOT_TOKEN — Telegram bot token for messaging-providers test (fake OK)
* DISCORD_BOT_TOKEN — Discord bot token for messaging-providers test (fake OK)
* SLACK_BOT_TOKEN — Slack bot token for messaging-providers test (fake OK)
* SLACK_APP_TOKEN — Slack app token for messaging-providers test (fake OK)
* SLACK_BOT_TOKEN_REVOKED — Revoked xoxb- token to test auth pre-validation (#2340)
* SLACK_APP_TOKEN_REVOKED — Paired xapp- token for the revoked bot token
* TELEGRAM_BOT_TOKEN_REAL — Real Telegram token for optional live round-trip
* DISCORD_BOT_TOKEN_REAL — Real Discord token for optional live round-trip
* TELEGRAM_CHAT_ID_E2E — Telegram chat ID for optional sendMessage test
Expand Down Expand Up @@ -143,6 +147,10 @@ function sshEnv(cmd, { timeout = 600_000, stream = false } = {}) {
for (const key of [
"TELEGRAM_BOT_TOKEN",
"DISCORD_BOT_TOKEN",
"SLACK_BOT_TOKEN",
"SLACK_APP_TOKEN",
"SLACK_BOT_TOKEN_REVOKED",
"SLACK_APP_TOKEN_REVOKED",
"TELEGRAM_BOT_TOKEN_REAL",
"DISCORD_BOT_TOKEN_REAL",
"TELEGRAM_CHAT_ID_E2E",
Expand Down
Loading
Loading