Skip to content

Commit f180cc9

Browse files
Ani1357j-zimnowoda
andauthored
feat: fix open redirect vulnerability (#1899)
Co-authored-by: jeho <[email protected]>
1 parent 9b5ee85 commit f180cc9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

values/oauth2-proxy/oauth2-proxy-raw.gotmpl

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- $v := .Values }}
2+
{{- $escapedDomain := $v.cluster.domainSuffix | replace "." "\\." }}
23
{{- $domain := printf "auth.%s" $v.cluster.domainSuffix }}
34
{{- $consoleUrl := printf "https://console.%s" $v.cluster.domainSuffix }}
45
{{- $cm := $v.apps | get "cert-manager" }}
@@ -29,8 +30,20 @@ resources:
2930
nginx.ingress.kubernetes.io/auth-response-headers: Authorization
3031
{{- end }}
3132
nginx.ingress.kubernetes.io/configuration-snippet: |
32-
# rewrite auth redirects to original hosts
33-
rewrite ^/oauth2/redirect/(.*) https://$1 redirect;
33+
set $redirect_target "";
34+
35+
# if $request_uri starts with "/oauth2/redirect/", the $redirect_target will be set to whatever comes after that.
36+
# e.g. https://auth.lkeid.akamai-apl.net/oauth2/redirect/example.com/ will set $redirect_target to https://example.com/
37+
if ($request_uri ~* ^/oauth2/redirect/(.*)) {
38+
set $redirect_target $1;
39+
}
40+
41+
# if the redirect_target matches a cluster's subdomain it will redirect to the cluster's subdomain with the rest of the path.
42+
# e.g. https://auth.lkeid.akamai-apl.net/oauth2/redirect/console.lkeid.akamai-apl.net/ will redirect to console.lkeid.akamai-apl.net/
43+
# e.g. https://auth.lkeid.akamai-apl.net/oauth2/redirect/evil.com will not be processed by the ingress controller.
44+
if ($redirect_target ~* "^([a-zA-Z0-9-]+\.){{ $escapedDomain }}(%2F)?(/.*)?$") {
45+
return 302 https://$redirect_target;
46+
}
3447
{{- with $ingress | get "sourceIpAddressFiltering" nil }}
3548
nginx.ingress.kubernetes.io/whitelist-source-range: "{{ . }}"
3649
{{- end}}

0 commit comments

Comments
 (0)