allow redirects to whitelisted hosts with ports
This commit is contained in:
		
							parent
							
								
									62bf233682
								
							
						
					
					
						commit
						bfb22506ff
					
				|  | @ -505,7 +505,7 @@ func (p *OAuthProxy) IsValidRedirect(redirect string) bool { | ||||||
| 			return false | 			return false | ||||||
| 		} | 		} | ||||||
| 		for _, domain := range p.whitelistDomains { | 		for _, domain := range p.whitelistDomains { | ||||||
| 			if (redirectURL.Host == domain) || (strings.HasPrefix(domain, ".") && strings.HasSuffix(redirectURL.Host, domain)) { | 			if (redirectURL.Hostname() == domain) || (strings.HasPrefix(domain, ".") && strings.HasSuffix(redirectURL.Hostname(), domain)) { | ||||||
| 				return true | 				return true | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -225,6 +225,12 @@ func TestIsValidRedirect(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	invalidHTTPS2 := proxy.IsValidRedirect("https://evil.corp/redirect?rd=foo.bar") | 	invalidHTTPS2 := proxy.IsValidRedirect("https://evil.corp/redirect?rd=foo.bar") | ||||||
| 	assert.Equal(t, false, invalidHTTPS2) | 	assert.Equal(t, false, invalidHTTPS2) | ||||||
|  | 
 | ||||||
|  | 	validPort := proxy.IsValidRedirect("http://foo.bar:3838/redirect") | ||||||
|  | 	assert.Equal(t, true, validPort) | ||||||
|  | 
 | ||||||
|  | 	validPortSubdomain := proxy.IsValidRedirect("http://baz.bar.foo:3838/redirect") | ||||||
|  | 	assert.Equal(t, true, validPortSubdomain) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type TestProvider struct { | type TestProvider struct { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue