Skip to content

fix(gateway): fail-close Telegram auth when TELEGRAM_ALLOWED_USERS is empty; warn on ALLOW_ALL - #24667

Closed
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:fix/cx11-issue-24457-telegram-fail-closed
Closed

fix(gateway): fail-close Telegram auth when TELEGRAM_ALLOWED_USERS is empty; warn on ALLOW_ALL#24667
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:fix/cx11-issue-24457-telegram-fail-closed

Conversation

@wesleysimplicio

Copy link
Copy Markdown
Contributor

Problem

When TELEGRAM_ALLOWED_USERS is not set, TelegramAdapter._is_authorized_user() returns True — any Telegram account that discovers the bot gets full agent access (filesystem, terminal, GitHub credentials).

Additionally, there is no warning emitted when GATEWAY_ALLOW_ALL_USERS=true is active — the most dangerous open state passes silently.

Root cause

gateway/platforms/telegram.py:501:

allowed_csv = os.getenv("TELEGRAM_ALLOWED_USERS", "").strip()
if not allowed_csv:
    return True    # ← fails OPEN when env var is absent

gateway/run.py:3360: the startup warning only fires when not _any_allowlist and not _allow_all, so _allow_all=True produces no log output.

Fix

gateway/platforms/telegram.py — fail closed when no allowlist:

if not allowed_csv:
    _global_open = os.getenv("GATEWAY_ALLOW_ALL_USERS", "").lower() in ("true", "1", "yes")
    _tg_open = os.getenv("TELEGRAM_ALLOW_ALL_USERS", "").lower() in ("true", "1", "yes")
    return _global_open or _tg_open   # False unless operator explicitly opts in

gateway/run.py — loud warning when allow-all is active:

elif _allow_all:
    logger.warning(
        "SECURITY WARNING: Gateway is open to ALL users (*_ALLOW_ALL_USERS=true). ..."
    )

Tests

tests/gateway/test_telegram_auth_fail_closed.py (new, 6 tests):

Test Assertion
test_no_allowlist_no_allow_all_denies empty env → False
test_gateway_allow_all_permits GATEWAY_ALLOW_ALL_USERS=trueTrue
test_telegram_allow_all_permits TELEGRAM_ALLOW_ALL_USERS=1True
test_allowlist_match_permits matching ID in CSV → True
test_allowlist_mismatch_denies non-matching ID → False
test_wildcard_in_allowlist_permits_all * in CSV → True

All 6 pass.

Visual

flowchart TD
    A[_is_authorized_user called] --> B{TELEGRAM_ALLOWED_USERS set?}
    B -- yes --> C{user_id in allowlist or *?}
    C -- yes --> D[return True]
    C -- no --> E[return False]
    B -- no --> F{GATEWAY_ALLOW_ALL_USERS or TELEGRAM_ALLOW_ALL_USERS?}
    F -- yes --> D
    F -- no --> E
Loading

Closes #24457

… empty; warn on ALLOW_ALL

_is_authorized_user() returned True when TELEGRAM_ALLOWED_USERS was unset,
granting any Telegram user full agent access (filesystem, terminal, GitHub).

Fail closed by default: empty allowlist now returns False unless the operator
explicitly sets GATEWAY_ALLOW_ALL_USERS=true or TELEGRAM_ALLOW_ALL_USERS=true.

Also add a loud SECURITY WARNING log when any allow-all flag is active, so
operators are aware the gateway is open.

Closes NousResearch#24457

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 13, 2026 00:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter area/auth Authentication, OAuth, credential pools labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #24468 (earliest open fix implementing fail-closed Telegram auth with GATEWAY_ALLOW_ALL_USERS check). Also competes with #24602 and #21356. All fix #24457.

@wesleysimplicio

Copy link
Copy Markdown
Contributor Author

Closing in favor of #24468 (earliest open) per @alt-glitch's note — same fail-closed Telegram auth fix for #24457.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Telegram gateway can be open to all users by default / setup should fail closed

3 participants