Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Malformed callback redirect when it already contains query string #317

Copy link
Copy link

Description

@unrevised6419
Issue body actions

First of all, thanks for the library.

When I have a Provider callback that contains already a query string, the final redirect location seems to be malformed

Callback

http://localhost:3000/connect/keycloak/redirect?referrer=%2Fen%2Fsearch

Redirect Location

http://localhost:3000/connect/keycloak/redirect?referrer=%2Fen%2Fsearch?id_token=abcdefg

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

let url = new URL(`http://localhost:3000/connect/keycloak/redirect?referrer=%2Fen%2Fsearch?id_token=abcdefg`)

console.log(url.searchParams.get('id_token')) // null
console.log(url.searchParams.get('referrer')) // "/en/search?id_token=abcdefg"

This comes from this line

? `${provider.callback || '/'}?${qs.stringify(output)}`

Meanwhile, this gets fixed, I'm using this patch workaround

patches/grant+5.4.24.patch

diff --git a/node_modules/grant/lib/response.js b/node_modules/grant/lib/response.js
index e67a013..430f746 100644
--- a/node_modules/grant/lib/response.js
+++ b/node_modules/grant/lib/response.js
@@ -105,7 +105,8 @@ var transport = ({provider, input, input:{params, state, session}, output}) => (
     ? output
 
     : (!provider.transport || provider.transport === 'querystring')
-    ? `${provider.callback || '/'}?${qs.stringify(output)}`
+    /* https://github.com/simov/grant/pull/329 */
+    ? `${provider.callback || '/'}${(provider.callback || '').includes('?') ? '&' : '?'}${qs.stringify(output)}`
 
     : provider.transport === 'session'
     ? provider.callback

Redirect Location with patch

http://localhost:3000/connect/keycloak/redirect?referrer=%2Fen%2Fsearch&id_token=abcdef
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.