fix(discord): DISCORD_ALLOW_BOTS=mentions/all now works without DISCORD_ALLOWED_USERS#4477
fix(discord): DISCORD_ALLOW_BOTS=mentions/all now works without DISCORD_ALLOWED_USERS#4477gnanam1990 wants to merge 2 commits into
Conversation
…ing lowercase variables The _ENV_ASSIGN_RE pattern was compiled with re.IGNORECASE, causing it to match lowercase variable assignments like `token = await ...` and `before_tokens = response.usage` as if they were secret environment variables. This caused two reported bugs: - NousResearch#4367: Python variable assignments (before_tokens, api_key, my_token) being incorrectly redacted in logs and tool output - NousResearch#4451: TypeScript/JS `await` keyword corrupted to `***` in patch tool output because `const token = await getToken()` matched the pattern, replacing `await` with `***` and stripping the surrounding whitespace Fix: remove re.IGNORECASE so only ALL-UPPERCASE env var names match. Add (?:^|(?<=\s)) lookbehind to prevent the pattern from consuming leading whitespace (e.g. `export SECRET=...` preserved correctly). Adds regression tests covering both Python and TypeScript/JS cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…RD_ALLOWED_USERS The _is_allowed_user() check in on_message ran before the DISCORD_ALLOW_BOTS filter, so bot messages were silently dropped when the bot's user ID was not in DISCORD_ALLOWED_USERS — before DISCORD_ALLOW_BOTS was ever consulted. A second gate in _is_user_authorized() (gateway/run.py) then rejected the same bots with "Unauthorized user" even when they passed the Discord-level bot filter. Fix: - discord.py on_message: move DISCORD_ALLOW_BOTS check before _is_allowed_user so bots permitted by mentions/all bypass the user allowlist entirely - session.py SessionSource: add is_bot: bool = False field - base.py build_source: expose is_bot parameter and pass it through - discord.py _handle_message: set is_bot=True for bot authors on the source - run.py _is_user_authorized: skip the user allowlist for Discord bot senders when DISCORD_ALLOW_BOTS is mentions or all Fixes NousResearch#4466 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Your core fix commit We dropped the Thanks for the thorough root-cause writeup and the precise code pointers — made this a fast review. |
Root Cause
Two sequential authorization gates both independently blocked bot messages, making
DISCORD_ALLOW_BOTScompletely ineffective:Gate 1 —
discord.pyon_message(line ~552 onmain):Gate 2 —
gateway/run.py_is_user_authorized:Even if a bot somehow passed Gate 1, the gateway-level allowlist check would reject it, producing the
WARNING gateway.run: Unauthorized user: <bot_id>message reported in the issue.Fix
gateway/platforms/discord.py— reorderon_messagechecks soDISCORD_ALLOW_BOTSruns before_is_allowed_user. Bots that pass the bot filter (mentions/all) skip the user allowlist entirely; non-bots are still checked as before.gateway/session.py— addis_bot: bool = FalsetoSessionSourceso the gateway layer can distinguish bot senders.gateway/platforms/base.py— exposeis_botparameter inbuild_sourceand pass it through toSessionSource.gateway/platforms/discord.py_handle_message— setis_bot=Truefor bot authors when buildingSessionSource.gateway/run.py_is_user_authorized— whensource.is_botisTrueandDISCORD_ALLOW_BOTSismentionsorall, returnTrueearly (platform filter already validated the message).Result
DISCORD_ALLOW_BOTS=none(default)DISCORD_ALLOW_BOTS=allDISCORD_ALLOW_BOTS=mentions+ bot @mentions HermesDISCORD_ALLOW_BOTS=mentions+ no mentionDISCORD_ALLOWED_USERSDISCORD_ALLOWED_USERSFixes #4466
🤖 Generated with Claude Code