You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Malformed callback redirect when it already contains query string #317
As you can see the query symbol (?) is already included in the Callback.
When the Redirect Location is created, the query symbol gets added again (see before id_token).
This issue creates problems when you try to parse the final URL
I see, thanks for sharing it. Not sure at what point precisely you add that additional querystring parameter to the callback URL (assuming that it is dynamic), but alternatively you can have a handler before the Grant middleware where you read that value and put it in session instead, you can even put it in the Grant session itself https://github.com/simov/grant/blob/master/examples/dynamic-state/express.js and then inside the final callback route you can read it back from the session.
I'm using Strapi which uses grant/koa, and I don't have full control over it.
When the user clicks the login URL on web these redirects happen
web: the front face of the website cms: Strapi instance sso: Keycloack instance
We have these endpoints
sso/login: sso login endpoint
cms/keycloack: cms connect keycloack endpoint (does not create any user)
cms/keycloack-callback: cms connect keycloack endpoint callback (does not create any user)
web/callback: web endpoint that is called after login to call cms back to create the user
cms/create: cms endpoint receives provider access token and creates the user
Callback
http://localhost:3000/connect/keycloak/redirect?referrer=%2Fen%2Fsearch&access_token=abcdef
^ ^ ^ sso provider token
^ ^ user land in the end
^ this calls cms/create
web redirects to cms/keycloack
cms/keycloack goes to sso/login
User enters login info in the form, submits
sso/login redirects to cms/keycloack-callback
cms/keycloack-callback redirects to web/callback
web/callback calls cms/create
web/callback stores the session, and redirects to referrer from URL
I cannot change web/callback to anything arbitrary, that needs to be an endpoint that calls cms/create. That's why I put the real callback where user needs to land in the end in the query string.
Activity
simov commentedon Feb 19, 2025
I see, thanks for sharing it. Not sure at what point precisely you add that additional querystring parameter to the callback URL (assuming that it is dynamic), but alternatively you can have a handler before the Grant middleware where you read that value and put it in session instead, you can even put it in the Grant session itself https://github.com/simov/grant/blob/master/examples/dynamic-state/express.js and then inside the final
callbackroute you can read it back from the session.unrevised6419 commentedon Feb 19, 2025
I'm using Strapi which uses
grant/koa, and I don't have full control over it.When the user clicks the login URL on
webthese redirects happenweb: the front face of the websitecms: Strapi instancesso: Keycloack instanceWe have these endpoints
sso/login:ssologin endpointcms/keycloack:cmsconnect keycloack endpoint (does not create any user)cms/keycloack-callback:cmsconnect keycloack endpoint callback (does not create any user)web/callback:webendpoint that is called after login to callcmsback to create the usercms/create:cmsendpoint receives provider access token and creates the userCallback
webredirects tocms/keycloackcms/keycloackgoes tosso/loginsso/loginredirects tocms/keycloack-callbackcms/keycloack-callbackredirects toweb/callbackweb/callbackcallscms/createweb/callbackstores the session, and redirects toreferrerfrom URLI cannot change
web/callbackto anything arbitrary, that needs to be an endpoint that callscms/create. That's why I put the real callback where user needs to land in the end in the query string.I hope this was clear 😂
simov commentedon Feb 23, 2025
Thanks for the thorough explanation, I might reconsider this feature 👍
fix(response): allow callback with query string