CVE-2021-21291

CVE-2021-21291 is a low-severity open redirect vulnerability in github.com/oauth2-proxy/oauth2-proxy/v7 (go), affecting versions < 7.0.0. It is fixed in 7.0.0.

Summary

Workarounds

Is there a way for users to fix or remediate the vulnerability without upgrading?
Disable the whitelist domain feature and run separate OAuth2 Proxy instances for each subdomain.

Original Issue Posted by @semoac:

Whitelist Domain feature is not working as expected because is not matching a dot to ensure the redirect is a subdomain.

Expected Behavior

If whitelist domain is set to .example.com , then hack.alienexample.com should be rejected as a valid redirect.

Current Behavior

The code is removing the dot from .example.com and only checking if the redirect string end with example.com

Possible Solution

Here
https://github.com/oauth2-proxy/oauth2-proxy/blob/c377466411f2aee180a732187edb638f2f7e57fb/oauthproxy.go#L661

Include the dot when checking the string:

strings.HasSuffix(redirectHostname, "." + domainHostname)

Steps to Reproduce (for bugs)

package main

import (
	"fmt"
	"strings"
)

func validOptionalPort(port string) bool {
	if port == "" || port == ":*" {
		return true
	}
	if port[0] != ':' {
		return false
	}
	for _, b := range port[1:] {
		if b < '0' || b > '9' {
			return false
		}
	}
	return true
}

func splitHostPort(hostport string) (host, port string) {
	host = hostport

	colon := strings.LastIndexByte(host, ':')
	if colon != -1 && validOptionalPort(host[colon:]) {
		host, port = host[:colon], host[colon+1:]
	}

	if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
		host = host[1 : len(host)-1]
	}

	return
}

func main() {
	domain := ".example.com"
	domainHostname, _ := splitHostPort(strings.TrimLeft(domain, "."))
	redirectHostname := "https://hack.alienexample.com"
	if (strings.HasPrefix(domain, ".") && strings.HasSuffix(redirectHostname, domainHostname)) { fmt.Println("This should not have happen.")}
}

Users of github.com/oauth2-proxy/oauth2-proxy are advised to update to github.com/oauth2-proxy/oauth2-proxy/v7

Impact

What kind of vulnerability is it? Who is impacted?
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.

Untrusted input controls a URL used for redirection, which can forward users to attacker-controlled sites. Typical impact: phishing and credential harvesting via a trusted domain.

CVE-2021-21291 has a CVSS score of 5.4 (Low). The vector is network-reachable, no privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (7.0.0); upgrading removes the vulnerable code path.

Affected versions

github.com/oauth2-proxy/oauth2-proxy/v7 (< 7.0.0) github.com/oauth2-proxy/oauth2-proxy (<= 3.2.0)

Security releases

github.com/oauth2-proxy/oauth2-proxy/v7 → 7.0.0 (go)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

See it in your environment

Remediation advice

Has the problem been patched? What versions should users upgrade to?
This is fixed in version 7.0.0 onwards.

Frequently Asked Questions

  1. What is CVE-2021-21291? CVE-2021-21291 is a low-severity open redirect vulnerability in github.com/oauth2-proxy/oauth2-proxy/v7 (go), affecting versions < 7.0.0. It is fixed in 7.0.0. Untrusted input controls a URL used for redirection, which can forward users to attacker-controlled sites.
  2. How severe is CVE-2021-21291? CVE-2021-21291 has a CVSS score of 5.4 (Low). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which packages are affected by CVE-2021-21291?
    • github.com/oauth2-proxy/oauth2-proxy/v7 (go) (versions < 7.0.0)
    • github.com/oauth2-proxy/oauth2-proxy (go) (versions <= 3.2.0)
  4. Is there a fix for CVE-2021-21291? Yes. CVE-2021-21291 is fixed in 7.0.0. Upgrade to this version or later.
  5. Is CVE-2021-21291 exploitable, and should I be worried? Whether CVE-2021-21291 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2021-21291 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2021-21291? Upgrade github.com/oauth2-proxy/oauth2-proxy/v7 to 7.0.0 or later.

Other vulnerabilities in github.com/oauth2-proxy/oauth2-proxy/v7

CVE-2026-41059CVE-2026-40574CVE-2026-40575CVE-2026-34457CVE-2026-34454

Stop the waste.
Protect your environment with Kodem.