Skip to content

fix(gateway): harden malformed env port overrides - #20205

Closed
Frowtek wants to merge 1 commit into
NousResearch:mainfrom
Frowtek:fix/gateway-env-port-override-hardening
Closed

fix(gateway): harden malformed env port overrides#20205
Frowtek wants to merge 1 commit into
NousResearch:mainfrom
Frowtek:fix/gateway-env-port-override-hardening

Conversation

@Frowtek

@Frowtek Frowtek commented May 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR fixes a gateway config parsing bug where malformed environment values for BLUEBUBBLES_WEBHOOK_PORT or WECOM_CALLBACK_PORT could crash _apply_env_overrides() with a ValueError.

gateway/config.py already has _coerce_int() for defensive numeric parsing, but these two env override paths were still using raw int(...). This change switches them to _coerce_int(..., 8645) so invalid values fall back to the documented default port instead of crashing gateway startup or config loading.

Related Issue

No linked issue; found via code inspection.

Type of Change

  • 🐛 Bug fix

Changes Made

  • Updated gateway/config.py to use _coerce_int() for WECOM_CALLBACK_PORT and BLUEBUBBLES_WEBHOOK_PORT
  • Added regression tests in tests/gateway/test_config.py covering malformed env values for both ports

How to Test

  1. Before the fix, set either:

    • BLUEBUBBLES_SERVER_URL=http://localhost:1234
    • BLUEBUBBLES_PASSWORD=secret
    • BLUEBUBBLES_WEBHOOK_PORT=not-a-port

    or:

    • WECOM_CALLBACK_CORP_ID=corp-id
    • WECOM_CALLBACK_CORP_SECRET=corp-secret
    • WECOM_CALLBACK_PORT=not-a-port
  2. Call _apply_env_overrides(GatewayConfig()) or load gateway config. Before the fix, it raises ValueError. After the fix, it falls back to 8645.

  3. Run:

    • pytest tests/gateway/test_config.py -k MalformedEnvPortOverrides -q
    • pytest tests/gateway/test_config.py -q

Checklist

  • test added
  • tests passing
  • cross-platform behavior considered
  • only relevant changes included

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels May 5, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for identifying this malformed-environment startup failure mode. The requested behavior is already present on current main.

  • gateway/config.py:1918 and gateway/config.py:1974 now use getenv_int(..., 8645) for the two ports.
  • gateway/config.py:192-199 catches malformed integer values and returns the default instead of raising.
  • Commit a7dd98c8609c0d944e3c5dd0c5b9ee31dd99eb29 implemented this as part of the broader malformed numeric environment-variable hardening; it is contained in release v2026.7.1.
  • The linked duplicate discussion on fix(config): guard WECOM_CALLBACK_PORT/BLUEBUBBLES_WEBHOOK_PORT against malformed env var #48748 also records that this bug class was superseded by the canonical fix.

Automated hermes-sweeper review.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants