Skip to content

Commit 39334b6

Browse files
authored
Add URL encoding to auth_redir cookie value (#86)
Storing a URI directly in the auth_redir cookie without encoding has led to issues where browsers misinterpret special characters, like semicolons, as part of the cookie delimiter. This behavior results in the truncation of the URI at the special character, causing incomplete or incorrect redirection URLs after user authentication.
1 parent 8da37d2 commit 39334b6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

openid_connect.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ function codeExchange(r) {
197197
} else {
198198
r.variables.new_access_token = "";
199199
}
200+
200201
r.headersOut["Set-Cookie"] = "auth_token=" + r.variables.request_id + "; " + r.variables.oidc_cookie_flags;
201-
r.return(302, r.variables.redirect_base + r.variables.cookie_auth_redir);
202+
r.return(302, r.variables.redirect_base + decodeURIComponent(r.variables.cookie_auth_redir));
202203
}
203204
);
204205
} catch (e) {
@@ -283,8 +284,10 @@ function getAuthZArgs(r) {
283284
authZArgs += "&" + r.variables.oidc_authz_extra_args;
284285
}
285286

287+
var encodedRequestUri = encodeURIComponent(r.variables.request_uri);
288+
286289
r.headersOut['Set-Cookie'] = [
287-
"auth_redir=" + r.variables.request_uri + "; " + r.variables.oidc_cookie_flags,
290+
"auth_redir=" + encodedRequestUri + "; " + r.variables.oidc_cookie_flags,
288291
"auth_nonce=" + noncePlain + "; " + r.variables.oidc_cookie_flags
289292
];
290293

0 commit comments

Comments
 (0)