Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A escaped redirect_uri causes the "did not match URI from initial request." error. #2766

Open
3 tasks done
YasuhiroABE opened this issue Dec 28, 2022 · 0 comments · May be fixed by #3492
Open
3 tasks done

A escaped redirect_uri causes the "did not match URI from initial request." error. #2766

YasuhiroABE opened this issue Dec 28, 2022 · 0 comments · May be fixed by #3492

Comments

@YasuhiroABE
Copy link

Preflight Checklist

  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.

Version

2.35.3

Storage Type

SQLite

Installation Type

Custom container image

Expected Behavior

Hello,

I use the dex with my mediawiki enabled the OpenIDConnect extension, then I found an encoded URL related error for the redirect_uri query parameter.

I received the "redirect_uri did not match URI from initial request." response from dex due to the comparison of the unescaped redirect_uri with the encoded one.

I expected the last redirect_uri will be accepted as well as the initial request.

Root cause

I'm sure that the message comes from the following code.

// server/handlers.go:880

        if authCode.RedirectURI != redirectURI {
                s.tokenErrHelper(w, errInvalidRequest, "redirect_uri did not match URI from initial request.",
 http.StatusBadRequest)
                return
        }
  1. The authCode.RedirectURI is an output value of url.QueryUnescape(q.Get("redirect_uri")) at server/oauth2.go:418.
  2. The redirectURI is just the return value of r.PostFormValue("redirect_uri") at server/handlers.go:835.
    function.

I think the return value of r.PostFromValue("redirect_uri") should be processed by the url.QueryUnescape() as well as the initial request.

Actual Behavior

My mediawiki shows the following debug messages.

[PluggableAuth] Plugin name: OpenIDConnect
[OpenIDConnect] Redirect URL: http://localhost:8080/mediawiki/index.php/%E7%89%B9%E5%88%A5:PluggableAuthLogin
[OpenIDConnect] Jumbojett\OpenIDConnectClientException: redirect_uri did not match URI from initial request. in /var/www/html/mediawiki/extensions/OpenIDConnect/vendor/jumbojett/openid-connect-php/src/OpenIDConnectClient.php:310

Steps To Reproduce

No response

Additional Information

I've tested the following code, and it works well.

diff --git a/server/handlers.go b/server/handlers.go
index 11dcdd07..be50fdf5 100755
--- a/server/handlers.go
+++ b/server/handlers.go
@@ -832,7 +832,11 @@ func (s *Server) calculateCodeChallenge(codeVerifier, codeChallengeMethod string
 // handle an access token request https://tools.ietf.org/html/rfc6749#section-4.1.3
 func (s *Server) handleAuthCode(w http.ResponseWriter, r *http.Request, client storage.Client) {
        code := r.PostFormValue("code")
-       redirectURI := r.PostFormValue("redirect_uri")
+       redirectURI, err := url.QueryUnescape(r.PostFormValue("redirect_uri"))
+       if err != nil {
+               s.tokenErrHelper(w, errInvalidRequest, "No redirect_uri provided.", http.StatusBadRequest)
+               return
+       }
 
        if code == "" {
                s.tokenErrHelper(w, errInvalidRequest, `Required param: code.`, http.StatusBadRequest)

Configuration

redirectURIs:
  - http://localhost:8000/mediawiki/index.php/特別:PluggableAuthLogin

Logs

No response

@YasuhiroABE YasuhiroABE linked a pull request Apr 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant