Conversation
Co-authored-by: johnkors <206726+johnkors@users.noreply.github.com>
Co-authored-by: johnkors <206726+johnkors@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix distribution middleware to use OAuth state parameter
Redirect to the OAuth state parameter after a Slack install
Sep 18, 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.
SlackbotCodeTokenExchangeMiddlewarenever read thestateparameter that Slack round-trips through the OAuth flow, so every install ended on the single configuredSuccessRedirectUri. An app that can start an install from more than one place (public landing page, admin screen, ...) had no way to send the user back to where they started.On a successful install the middleware now prefers
stateas the redirect target, but only when it is a local url — otherwise the callback would be an open redirect.Changes
SlackbotCodeTokenExchangeMiddleware: readsstatefrom the callback query and resolves the redirect target. A localstateis resolved againstSuccessRedirectUri's origin when that option is an absolutehttp(s)uri (so the user stays on the same site), and used as-is when it is relative. Everything else falls back toSuccessRedirectUri.IsLocalUrlguard: mirrorsIUrlHelper.IsLocalUrlsemantics — accepts/foo, rejects absolute urls, protocol-relative//hostand/\host, anything not starting with a single/, and values containing control characters (a browser strips tabs/newlines, which can turn/\t/hostback into a protocol-relative url). NoteUri.TryCreate(..., UriKind.Absolute)is not usable as the rejection check here: on Unix/successparses as an absolutefile://uri.UseSlackbotDistributionandOAuthOptions.SuccessRedirectUridescribe the precedence.DistributionRedirectTests: drives the real pipeline (AddSlackbotDistribution+UseSlackbotDistribution) against a stubbedoauth.v2.accessresponse and asserts theLocationheader for local, absolute, protocol-relative, backslash, non-rooted and emptystatevalues, plus that the workspace still reachesIWorkspaceInstallationHandler.The issue also floated handing raw
statetoIWorkspaceInstallationHandlerinstead; this takes the redirect route since it needs no change to the handler contract, and the two are not mutually exclusive if the hook is wanted later.