fix(gateway): prevent Discord role-allowlist auth bypass#12226
Closed
plgonzalezrx8 wants to merge 0 commit into
Closed
fix(gateway): prevent Discord role-allowlist auth bypass#12226plgonzalezrx8 wants to merge 0 commit into
plgonzalezrx8 wants to merge 0 commit into
Conversation
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.
Motivation
GatewayRunner._is_user_authorizedunconditionally authorized any Discord source wheneverDISCORD_ALLOWED_ROLESwas set, creating an authorization bypass for slash and other non-message interactions.MessageEventand callhandle_messagewithout going through the adapter'son_messagepre-filter, so the adapter-side role check cannot be assumed to have run.Description
DISCORD_ALLOWED_ROLESearly-return inGatewayRunner._is_user_authorizedwith an adapter-backed verification that calls the Discord adapter's_is_allowed_user(user_id)when available (gateway/run.py)._is_allowed_userreturns true the gateway authorizes early, otherwise authorization falls through to pairing, platform-specific allowlists, and global checks instead of granting access.tests/gateway/test_discord_bot_auth_bypass.pyto assert the new behavior, adding tests that require adapter verification, verify fail-closed when adapter verification is missing, and ensureDISCORD_ALLOWED_USERSstill authorizes via the normal allowlist path.Testing
python -m pytest -o addopts='' tests/gateway/test_discord_bot_auth_bypass.py -qand all tests passed (10 passed).scripts/run_tests.shbut it could not be executed in this environment due to missing project virtualenv (.venv/venv), so CI-style wrapper was not run here.