@@ -98,6 +98,7 @@ type OAuthProxy struct {
98
98
forceJSONErrors bool
99
99
realClientIPParser ipapi.RealClientIPParser
100
100
trustedIPs * ip.NetSet
101
+ statePostfix string
101
102
102
103
sessionChain alice.Chain
103
104
headersChain alice.Chain
@@ -235,6 +236,7 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr
235
236
upstreamProxy : upstreamProxy ,
236
237
redirectValidator : redirectValidator ,
237
238
appDirector : appDirector ,
239
+ statePostfix : opts .StatePostfix ,
238
240
}
239
241
p .buildServeMux (opts .ProxyPrefix )
240
242
@@ -787,7 +789,7 @@ func (p *OAuthProxy) doOAuthStart(rw http.ResponseWriter, req *http.Request, ove
787
789
callbackRedirect := p .getOAuthRedirectURI (req )
788
790
loginURL := p .provider .GetLoginURL (
789
791
callbackRedirect ,
790
- encodeState (csrf .HashOAuthState (), appRedirect ),
792
+ encodeState (csrf .HashOAuthState (), appRedirect , p . statePostfix ),
791
793
csrf .HashOIDCNonce (),
792
794
extraParams ,
793
795
)
@@ -845,7 +847,8 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
845
847
846
848
csrf .ClearCookie (rw , req )
847
849
848
- nonce , appRedirect , err := decodeState (req )
850
+ nonce , appRedirect , _ , err := decodeState (req )
851
+
849
852
if err != nil {
850
853
logger .Errorf ("Error while parsing OAuth2 state: %v" , err )
851
854
p .ErrorPage (rw , req , http .StatusInternalServerError , err .Error ())
@@ -1185,18 +1188,20 @@ func checkAllowedEmails(req *http.Request, s *sessionsapi.SessionState) bool {
1185
1188
1186
1189
// encodedState builds the OAuth state param out of our nonce and
1187
1190
// original application redirect
1188
- func encodeState (nonce string , redirect string ) string {
1189
- return fmt .Sprintf ("%v:%v" , nonce , redirect )
1191
+ func encodeState (nonce string , redirect string , additional string ) string {
1192
+ return fmt .Sprintf ("%v:%v:%v " , nonce , redirect , additional )
1190
1193
}
1191
1194
1192
1195
// decodeState splits the reflected OAuth state response back into
1193
1196
// the nonce and original application redirect
1194
- func decodeState (req * http.Request ) (string , string , error ) {
1195
- state := strings .SplitN (req .Form .Get ("state" ), ":" , 2 )
1196
- if len (state ) != 2 {
1197
- return "" , "" , errors .New ("invalid length" )
1197
+ func decodeState (req * http.Request ) (string , string , string , error ) {
1198
+ state := strings .SplitN (req .Form .Get ("state" ), ":" , 3 )
1199
+
1200
+ if len (state ) != 3 {
1201
+ return "" , "" , "" , errors .New ("invalid length" )
1198
1202
}
1199
- return state [0 ], state [1 ], nil
1203
+
1204
+ return state [0 ], state [1 ], state [2 ], nil
1200
1205
}
1201
1206
1202
1207
// addHeadersForProxying adds the appropriate headers the request / response for proxying
0 commit comments