@@ -118,65 +118,67 @@ test_auth () {
118
118
" ${proxy_scheme} ://localhost:${proxy_port} " \
119
119
" ${curl_args[@]} "
120
120
121
- # To enhance security,the nonce will always be used in the OAuth2 flow once PR https://github.com/envoyproxy/envoy/pull/35919 is merged .
122
- # Nonce-less verification will remain for backward compatibility with previous releases .
123
- # TODO: zhaohuabing - Remove the nonce-less verification after a reasonable transition period, such as one year.
124
- run_log " Check whether the nonce is used in the OAuth2 filter "
125
- SUPPORT_NONCE =" false"
121
+ # State has been changed to be a base64url encoded json object in #37473 .
122
+ # TODO(zhaohuabing): Remove the following code after #37473 is merged and become stable .
123
+ run_log " Check whether the state is a base64url encoded json object "
124
+ BASE64URL_PREFIX= " eyJ1cmwiOi " # The state is prefixed with this string when it is a base64url encoded json object ({"url":)
125
+ STATE_BASE64URL_ENCODE =" false" # Whether the state is a base64url encoded json object
126
126
LOCATION=$( _curl " ${curl_args[@]} " --head " ${proxy_scheme} ://localhost:${proxy_port} /login" | grep location)
127
- if [[ " $LOCATION " == * " nonce%3D " * ]]; then
128
- SUPPORT_NONCE =" true"
127
+ if [[ " $LOCATION " == * " $BASE64URL_PREFIX " * ]]; then
128
+ STATE_BASE64URL_ENCODE =" true"
129
129
fi
130
130
131
131
run_log " Inititiate login"
132
132
responds_with_header \
133
133
" HTTP/1.1 302 Found" \
134
134
" ${proxy_scheme} ://localhost:${proxy_port} /login" \
135
135
" ${curl_args[@]} "
136
- if [[ " $SUPPORT_NONCE " == " true" ]]; then
136
+ if [[ " $STATE_BASE64URL_ENCODE " == " true" ]]; then
137
137
responds_with_header \
138
- " location: http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D${proxy_scheme} %253A%252F%252Flocalhost%253A${proxy_port} %252Flogin%26nonce%3D" \
139
- " ${proxy_scheme} ://localhost:${proxy_port} /login" \
140
- " ${curl_args[@]} "
141
- responds_with_header \
142
- " set-cookie: OauthNonce=" \
138
+ " location: http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${BASE64URL_PREFIX} " \
143
139
" ${proxy_scheme} ://localhost:${proxy_port} /login" \
144
140
" ${curl_args[@]} "
145
141
else
146
142
responds_with_header \
147
- " location: http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${proxy_scheme} %3A%2F%2Flocalhost%3A ${proxy_port} %2Flogin " \
143
+ " location: http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D ${proxy_scheme} %253A%252F%252Flocalhost%253A ${proxy_port} %252Flogin%26nonce%3D " \
148
144
" ${proxy_scheme} ://localhost:${proxy_port} /login" \
149
145
" ${curl_args[@]} "
150
146
fi
147
+ responds_with_header \
148
+ " set-cookie: OauthNonce=" \
149
+ " ${proxy_scheme} ://localhost:${proxy_port} /login" \
150
+ " ${curl_args[@]} "
151
+
152
+ encoded_state=$( echo -n " {\" url\" :\" ${proxy_scheme} ://localhost:${proxy_port} /login\" ,\" nonce\" :\" 12345678\" }" | basenc --base64url --wrap=0 | sed ' s/=//g' )
151
153
152
154
run_log " Fetch the myhub authorization page"
153
- if [[ " $SUPPORT_NONCE " == " true" ]]; then
155
+ if [[ " $STATE_BASE64URL_ENCODE " == " true" ]]; then
154
156
responds_with_header \
155
157
" HTTP/1.1 302 Found" \
156
- " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D ${proxy_scheme} %253A%252F%252Flocalhost%253A ${proxy_port} %252Flogin%26nonce%3D12345678 " \
158
+ " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${encoded_state} " \
157
159
" ${curl_args[@]} "
158
160
responds_with_header \
159
161
" Location: ${proxy_scheme} ://localhost:${proxy_port} /authorize?code=" \
160
- " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D ${proxy_scheme} %253A%252F%252Flocalhost%253A ${proxy_port} %252Flogin%26nonce%3D12345678 " \
162
+ " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${encoded_state} " \
161
163
" ${curl_args[@]} "
162
164
else
163
165
responds_with_header \
164
166
" HTTP/1.1 302 Found" \
165
- " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${proxy_scheme} %3A%2F%2Flocalhost%3A ${proxy_port} %2Flogin " \
167
+ " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D ${proxy_scheme} %253A%252F%252Flocalhost%253A ${proxy_port} %252Flogin%26nonce%3D12345678 " \
166
168
" ${curl_args[@]} "
167
169
responds_with_header \
168
170
" Location: ${proxy_scheme} ://localhost:${proxy_port} /authorize?code=" \
169
- " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${proxy_scheme} %3A%2F%2Flocalhost%3A ${proxy_port} %2Flogin " \
171
+ " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D ${proxy_scheme} %253A%252F%252Flocalhost%253A ${proxy_port} %252Flogin%26nonce%3D12345678 " \
170
172
" ${curl_args[@]} "
171
173
fi
172
174
173
175
run_log " Return to the app and receive creds"
174
- if [[ " $SUPPORT_NONCE " == " true" ]]; then
176
+ if [[ " $STATE_BASE64URL_ENCODE " == " true" ]]; then
177
+ CODE=$( _curl " ${curl_args[@]} " --head " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${encoded_state} " | grep Location | cut -d= -f2 | cut -d\& -f1)
178
+ RESPONSE=$( _curl " ${curl_args[@]} " --cookie " OauthNonce=12345678" --head " ${proxy_scheme} ://localhost:${proxy_port} /authorize?code=$CODE &state=${encoded_state} " )
179
+ else
175
180
CODE=$( _curl " ${curl_args[@]} " --head " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3D${proxy_scheme} %253A%252F%252Flocalhost%253A${proxy_port} %252Flogin%26nonce%3D12345678" | grep Location | cut -d= -f2 | cut -d\& -f1)
176
181
RESPONSE=$( _curl " ${curl_args[@]} " --cookie " OauthNonce=12345678" --head " ${proxy_scheme} ://localhost:${proxy_port} /authorize?code=$CODE &state=url%3D${proxy_scheme} %253A%252F%252Flocalhost%253A${proxy_port} %252Flogin%26nonce%3D12345678" )
177
- else
178
- CODE=$( _curl " ${curl_args[@]} " --head " http://localhost:${PORT_MYHUB} /authorize?client_id=0123456789&redirect_uri=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Flogin" | grep Location | cut -d= -f2 | cut -d\& -f1)
179
- RESPONSE=$( _curl " ${curl_args[@]} " --head " ${proxy_scheme} ://localhost:${proxy_port} /authorize?code=$CODE &state=${proxy_scheme} %3A%2F%2Flocalhost%3A${proxy_port} %2Flogin" )
180
182
fi
181
183
echo " $RESPONSE " | grep " HTTP/1.1 302 Found"
182
184
echo " $RESPONSE " | grep " location: ${proxy_scheme} ://localhost:${proxy_port} /login"
@@ -326,16 +328,16 @@ run_log "Inititiate dev login (Github)"
326
328
responds_with_header \
327
329
" HTTP/1.1 302 Found" \
328
330
" http://localhost:${PORT_DEV_PROXY} /login"
329
- if [[ " $SUPPORT_NONCE " == " true" ]]; then
331
+ if [[ " $STATE_BASE64URL_ENCODE " == " true" ]]; then
330
332
responds_with_header \
331
- " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttp%253A%252F%252Flocalhost%253A ${PORT_DEV_PROXY} %252Flogin%26nonce%3D " \
333
+ " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${BASE64URL_PREFIX} " \
332
334
" http://localhost:${PORT_DEV_PROXY} /login"
333
335
responds_with_header \
334
336
" set-cookie: OauthNonce=" \
335
337
" http://localhost:${PORT_DEV_PROXY} /login"
336
338
else
337
339
responds_with_header \
338
- " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=http%3A%2F%2Flocalhost%3A ${PORT_DEV_PROXY} %2Flogin " \
340
+ " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttp%253A%252F%252Flocalhost%253A ${PORT_DEV_PROXY} %252Flogin%26nonce%3D " \
339
341
" http://localhost:${PORT_DEV_PROXY} /login"
340
342
fi
341
343
@@ -344,9 +346,9 @@ responds_with \
344
346
" Envoy single page app example" \
345
347
" https://localhost:${PORT_PROXY} " \
346
348
-k
347
- if [[ " $SUPPORT_NONCE " == " true" ]]; then
349
+ if [[ " $STATE_BASE64URL_ENCODE " == " true" ]]; then
348
350
responds_with_header \
349
- " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttps%253A%252F%252Flocalhost%253A ${PORT_PROXY} %252Flogin%26nonce%3D " \
351
+ " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=${BASE64URL_PREFIX} " \
350
352
" https://localhost:${PORT_PROXY} /login" \
351
353
-k
352
354
responds_with_header \
@@ -355,7 +357,7 @@ if [[ "$SUPPORT_NONCE" == "true" ]]; then
355
357
-k
356
358
else
357
359
responds_with_header \
358
- " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=https%3A%2F%2Flocalhost%3A ${PORT_PROXY} %2Flogin " \
360
+ " location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY} %2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttps%253A%252F%252Flocalhost%253A ${PORT_PROXY} %252Flogin%26nonce%3D " \
359
361
" https://localhost:${PORT_PROXY} /login" \
360
362
-k
361
363
fi
0 commit comments