Repository navigation
Description
Reproducible in:
The Slack SDK version
slack_sdk 3.48.0 (also main at 80f2f22)
Python runtime version
Python 3.13.18
OS info
macOS (not OS-specific)
Steps to reproduce:
AuthorizeUrlGenerator.generate() and OpenIDConnectAuthorizeUrlGenerator.generate() put state, redirect_uri, team, nonce and the other values into the query string without URL-encoding them. A value that contains &, ?, = or + changes the meaning of the generated URL.
from urllib.parse import parse_qs, urlparse
from slack_sdk.oauth import AuthorizeUrlGenerator
redirect_uri = "https://example.com/slack/oauth_redirect?tenant=acme&env=prod"
state = "a+b/c==" # for example a base64 value issued by a custom OAuthStateStore
generator = AuthorizeUrlGenerator(
client_id="111.222",
scopes=["chat:write"],
redirect_uri=redirect_uri,
)
url = generator.generate(state=state)
params = parse_qs(urlparse(url).query, keep_blank_values=True)
print(url)
print(params["redirect_uri"])
print(params["state"])
print(params.get("env"))Expected result:
The URL carries the values that were passed in:
['https://example.com/slack/oauth_redirect?tenant=acme&env=prod']
['a+b/c==']
None
Actual result:
https://slack.com/oauth/v2/authorize?state=a+b/c==&client_id=111.222&scope=chat:write&user_scope=&redirect_uri=https://example.com/slack/oauth_redirect?tenant=acme&env=prod
['https://example.com/slack/oauth_redirect?tenant=acme']
['a b/c==']
['prod']
redirect_uriis cut at its first&, and the rest (env=prod) becomes a separate parameter of the authorize request.- The
+instateis read as a space, so the state that comes back in the callback no longer matches the one that was issued.
OpenIDConnectAuthorizeUrlGenerator behaves the same way, including for nonce.
I have a fix with tests and will open a pull request for it. It percent-encodes each value and keeps :, / and , as they are, so the URLs generated for values without reserved characters do not change.
Requirements
For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
Activity