{"id":"CVE-2021-21291","aliases":["CVE-2021-21291","GHSA-4mf2-f3wh-gvf2","BIT-OAUTH2-PROXY-2021-21291","GO-2022-0790"],"related":[],"kind":"vulnerability","state":"published","title":"Subdomain checking of whitelisted domains could allow unintended redirects","summary":"OAuth2 Proxy is an open-source reverse proxy and static file server that provides authentication using Providers (Google, GitHub, and others) to validate accounts by email, domain or group. In OAuth2 Proxy before version 7.0.0, for users that use the whitelist domain feature, a domain that ended in a similar way to the intended domain could have been allowed as a redirect. For example, if a whitelist domain was configured for \".example.com\", the intention is that subdomains of example.com are allowed. Instead, \"example.com\" and \"badexample.com\" could also match. This is fixed in version 7.0.0 onwards. As a workaround, one can disable the whitelist domain feature and run separate OAuth2 Proxy instances for each subdomain.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"OAuth2 Proxy is an open-source reverse proxy and static file server that provides authentication using Providers (Google, GitHub, and others) to validate accounts by email, domain or group. In OAuth2 Proxy before version 7.0.0, for users that use the whitelist domain feature, a domain that ended in a similar way to the intended domain could have been allowed as a redirect. For example, if a whitelist domain was configured for \".example.com\", the intention is that subdomains of example.com are allowed. Instead, \"example.com\" and \"badexample.com\" could also match. This is fixed in version 7.0.0 onwards. As a workaround, one can disable the whitelist domain feature and run separate OAuth2 Proxy instances for each subdomain.","source":"cvelist"},{"lang":"en","text":"### Impact\n_What kind of vulnerability is it? Who is impacted?_\nFor users that use the whitelist domain feature, a domain that ended in a similar way to the intended domain could have been allowed as a redirect.\n\nFor example, if a whitelist domain was configured for `.example.com`, the intention is that subdomains of `example.com` are allowed.\nInstead, `example.com` and `badexample.com` could also match.\n\n### Patches\n_Has the problem been patched? What versions should users upgrade to?_\nThis is fixed in version 7.0.0 onwards.\n\n### Workarounds\n_Is there a way for users to fix or remediate the vulnerability without upgrading?_\nDisable the whitelist domain feature and run separate OAuth2 Proxy instances for each subdomain.\n\n# Original Issue Posted by @semoac:\n\nWhitelist Domain feature is not working as expected because is not matching a dot to ensure the redirect is a subdomain.\n\n## Expected Behavior\n\nIf whitelist domain is set to `.example.com` , then `hack.alienexample.com`  should be rejected as a valid redirect.\n\n## Current Behavior\n\nThe code is removing the `dot`  from `.example.com`  and  only checking if the redirect string end with `example.com`\n\n## Possible Solution\nHere\nhttps://github.com/oauth2-proxy/oauth2-proxy/blob/c377466411f2aee180a732187edb638f2f7e57fb/oauthproxy.go#L661\n\nInclude the dot when checking the string:\n```\nstrings.HasSuffix(redirectHostname, \".\" + domainHostname)\n```\n\n## Steps to Reproduce (for bugs)\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc validOptionalPort(port string) bool {\n\tif port == \"\" || port == \":*\" {\n\t\treturn true\n\t}\n\tif port[0] != ':' {\n\t\treturn false\n\t}\n\tfor _, b := range port[1:] {\n\t\tif b < '0' || b > '9' {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nfunc splitHostPort(hostport string) (host, port string) {\n\thost = hostport\n\n\tcolon := strings.LastIndexByte(host, ':')\n\tif colon != -1 && validOptionalPort(host[colon:]) {\n\t\thost, port = host[:colon], host[colon+1:]\n\t}\n\n\tif strings.HasPrefix(host, \"[\") && strings.HasSuffix(host, \"]\") {\n\t\thost = host[1 : len(host)-1]\n\t}\n\n\treturn\n}\n\nfunc main() {\n\tdomain := \".example.com\"\n\tdomainHostname, _ := splitHostPort(strings.TrimLeft(domain, \".\"))\n\tredirectHostname := \"https://hack.alienexample.com\"\n\tif (strings.HasPrefix(domain, \".\") && strings.HasSuffix(redirectHostname, domainHostname)) { fmt.Println(\"This should not have happen.\")}\n}\n\n```\n\nUsers of `github.com/oauth2-proxy/oauth2-proxy` are advised to update to `github.com/oauth2-proxy/oauth2-proxy/v7`","format":"markdown","source":"ghsa"},{"lang":"en","text":"Subdomain checking of whitelisted domains could allow unintended redirects in oauth2-proxy in github.com/oauth2-proxy/oauth2-proxy","format":"markdown","source":"go"},{"lang":"es","text":"OAuth2 Proxy es un proxy inverso de código abierto y un servidor de archivos estáticos que proporciona autenticación usando Proveedores (Google, GitHub y otros) para comprobar cuentas por correo electrónico, dominio o grupo.&#xa0;En OAuth2 Proxy versiones anteriores a 7.0.0, para los usuarios que usan la funcionalidad whitelist domain, se podría haber permitido como redireccionamiento un dominio que terminara de manera similar al dominio deseado.&#xa0;Por ejemplo, si se configuró un dominio de lista blanca para \".example.com\", la intención es que se permitan los subdominios de example.com.&#xa0;En su lugar, \"example.com\" y \"badexample.com\" también podrían coincidir.&#xa0;Esto es corregido en versión 7.0.0 en adelante.&#xa0;Como solución alternativa, se puede deshabilitar la funcionalidad whitelist domain y ejecutar instancias de proxy OAuth2 separadas para cada subdominio","source":"nvd"}],"published":"2021-02-02T19:05:18.000Z","modified":"2026-09-10T03:49:04.327Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","score":5.4,"rating":"LOW"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:M/Au:N/C:P/I:P/A:N","score":5.8,"rating":"MEDIUM"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"MEDIUM"}],"cwes":["CWE-601"],"affected":[{"ranges":[{"version":"< 7.0.0","status":"affected"}],"vendor":"oauth2-proxy","product":"oauth2-proxy","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"7.0.0"}],"ecosystem":"Go","package":"github.com/oauth2-proxy/oauth2-proxy/v7","purl":"pkg:golang/github.com/oauth2-proxy/oauth2-proxy/v7","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","lastAffected":"3.2.0"}],"ecosystem":"Go","package":"github.com/oauth2-proxy/oauth2-proxy","purl":"pkg:golang/github.com/oauth2-proxy/oauth2-proxy","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected"}],"ecosystem":"Go","package":"github.com/oauth2-proxy/oauth2-proxy","purl":"pkg:golang/github.com/oauth2-proxy/oauth2-proxy","source":"go"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"7.0.0"}],"ecosystem":"Go","package":"github.com/oauth2-proxy/oauth2-proxy/v7","purl":"pkg:golang/github.com/oauth2-proxy/oauth2-proxy/v7","source":"go"},{"ranges":[{"status":"affected","fixed":"7.0.0"}],"vendor":"oauth2_proxy_project","product":"oauth2_proxy","cpe":"cpe:2.3:a:oauth2_proxy_project:oauth2_proxy:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"7.0.0"}],"ecosystem":"Bitnami","package":"oauth2-proxy","purl":"pkg:bitnami/oauth2-proxy","source":"bitnami"}],"references":[{"url":"https://github.com/oauth2-proxy/oauth2-proxy/security/advisories/GHSA-4mf2-f3wh-gvf2","tags":["advisory","exploit","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","go","nvd","bitnami"]},{"url":"https://github.com/oauth2-proxy/oauth2-proxy/releases/tag/v7.0.0","tags":["advisory","release-notes","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","go","nvd","bitnami"]},{"url":"https://pkg.go.dev/github.com/oauth2-proxy/oauth2-proxy/v7","tags":["advisory","product","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","go","nvd","bitnami"]},{"url":"https://github.com/oauth2-proxy/oauth2-proxy/commit/780ae4f3c99b579cb2ea9845121caebb6192f725","tags":["advisory","fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","go","nvd","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21291","tags":["advisory","web"],"sources":["ghsa","go","bitnami"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-21291","url":"https://www.cve.org/CVERecord?id=CVE-2021-21291","licence":"CVE Terms of Use","modified":"2024-08-03T18:09:15.152Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-4mf2-f3wh-gvf2","url":"https://github.com/advisories/GHSA-4mf2-f3wh-gvf2","licence":"CC-BY-4.0","modified":"2026-09-10T03:49:04.327Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2022-0790","url":"https://pkg.go.dev/vuln/GO-2022-0790","licence":"CC-BY-4.0","modified":"2026-03-03T04:50:53.714Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-21291","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21291","licence":"Public domain","modified":"2026-06-17T03:35:12.840Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-OAUTH2-PROXY-2021-21291","url":"https://osv.dev/vulnerability/BIT-OAUTH2-PROXY-2021-21291","licence":"Apache-2.0","modified":"2026-09-08T08:48:10.807Z"}],"updatedAt":"2026-11-25T22:57:59.776Z","epss":{"score":0.01595,"percentile":0.76443,"date":"2026-12-01T12:00:22.000Z"}}