disable device code endpoint if not granted - #6
Merged
pascal-fischer merged 1 commit intoJul 16, 2026
Conversation
📝 WalkthroughWalkthroughDevice-related endpoints are now registered only when the device code grant is supported. Integration tests verify that these routes return 404 when disabled and remain accessible with the default device-grant configuration. ChangesDevice grant endpoint gating
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
braginini
approved these changes
Jul 16, 2026
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.
Summary
Dex lets operators restrict which grants a server supports via oauth2.grantTypes (Config.AllowedGrantTypes). A common hardening step is to remove the
device authorization grant (urn:ietf:params:oauth:grant-type:device_code, RFC 8628) to prevent device-code phishing.
Today that setting does not actually disable the device flow. Removing device_code from AllowedGrantTypes only:
But the device endpoints themselves — /device, /device/code, /device/auth/verify_code, /device/token, /device/callback — are registered unconditionally,
and none of their handlers consult supportedGrantTypes. In particular, the deprecated /device/token endpoint calls handleDeviceToken directly and never
passes through the grant-type check that /token enforces.
Net effect: an operator who disables the device grant still exposes a fully functional device flow and can still have tokens minted through it — a silent
bypass of a security control.
Why it's still exploitable with the grant "removed"
The only enforcement point for grant types is in handleToken (s.supportedGrantTypes check). The device-flow handlers don't share it:
supportedGrantTypes.
So a client that just avoids the "blocked" /token path and polls the legacy /device/token path completes the whole flow.
Exploit — device-code phishing (unauthenticated attacker)
"disabled".)
identity.
No attacker-controlled redirect URI, no credentials, no client secret — the attacker only needs a registered public client id (device-flow clients are public by design).