@@ -3,10 +3,8 @@ package identityprovider
3
3
import (
4
4
"database/sql"
5
5
"errors"
6
- "fmt"
7
6
"net/http"
8
7
"net/url"
9
- "strings"
10
8
"time"
11
9
12
10
"github.com/google/uuid"
@@ -40,7 +38,7 @@ func extractAuthorizeParams(r *http.Request, callbackURL string) (authorizeParam
40
38
}
41
39
params := authorizeParams {
42
40
clientID : p .String (vals , "" , "client_id" ),
43
- redirectURL : p .URL (vals , cb , "redirect_uri" ),
41
+ redirectURL : p .RedirectURL (vals , cb , "redirect_uri" ),
44
42
responseType : httpapi .ParseCustom (p , vals , "" , "response_type" , httpapi .ParseEnum [codersdk .OAuth2ProviderResponseType ]),
45
43
scope : p .Strings (vals , []string {}, "scope" ),
46
44
state : p .String (vals , "" , "state" ),
@@ -49,13 +47,6 @@ func extractAuthorizeParams(r *http.Request, callbackURL string) (authorizeParam
49
47
// We add "redirected" when coming from the authorize page.
50
48
_ = p .String (vals , "" , "redirected" )
51
49
52
- if err := validateRedirectURL (cb , params .redirectURL .String ()); err != nil {
53
- p .Errors = append (p .Errors , codersdk.ValidationError {
54
- Field : "redirect_uri" ,
55
- Detail : fmt .Sprintf ("Query param %q is invalid" , "redirect_uri" ),
56
- })
57
- }
58
-
59
50
p .ErrorExcessParams (vals )
60
51
return params , p .Errors , nil
61
52
}
@@ -143,17 +134,3 @@ func Authorize(db database.Store, accessURL *url.URL) http.HandlerFunc {
143
134
// Always wrap with its custom mw.
144
135
return authorizeMW (accessURL )(http .HandlerFunc (handler )).ServeHTTP
145
136
}
146
-
147
- // validateRedirectURL validates that the redirectURL is contained in baseURL.
148
- func validateRedirectURL (baseURL * url.URL , redirectURL string ) error {
149
- redirect , err := url .Parse (redirectURL )
150
- if err != nil {
151
- return err
152
- }
153
- // It can be a sub-directory but not a sub-domain, as we have apps on
154
- // sub-domains so it seems too dangerous.
155
- if redirect .Host != baseURL .Host || ! strings .HasPrefix (redirect .Path , baseURL .Path ) {
156
- return xerrors .New ("invalid redirect URL" )
157
- }
158
- return nil
159
- }
0 commit comments