|
8 | 8 | "html/template" |
9 | 9 | "io/ioutil" |
10 | 10 | "log" |
| 11 | + "net" |
11 | 12 | "net/http" |
12 | 13 | "net/http/httputil" |
13 | 14 | "net/url" |
@@ -244,25 +245,38 @@ func jwtDecodeSegment(seg string) ([]byte, error) { |
244 | 245 | } |
245 | 246 |
|
246 | 247 | func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) { |
247 | | - domain := strings.Split(req.Host, ":")[0] |
248 | | - if p.CookieDomain != "" && strings.HasSuffix(domain, p.CookieDomain) { |
| 248 | + domain := req.Host |
| 249 | + if h, _, err := net.SplitHostPort(domain); err == nil { |
| 250 | + domain = h |
| 251 | + } |
| 252 | + if p.CookieDomain != "" { |
| 253 | + if !strings.HasSuffix(domain, p.CookieDomain) { |
| 254 | + log.Printf("Warning: request host is %q but using configured cookie domain of %q", domain, p.CookieDomain) |
| 255 | + } |
249 | 256 | domain = p.CookieDomain |
250 | 257 | } |
251 | 258 | cookie := &http.Cookie{ |
252 | 259 | Name: p.CookieKey, |
253 | 260 | Value: "", |
254 | 261 | Path: "/", |
255 | 262 | Domain: domain, |
256 | | - Expires: time.Now().Add(time.Duration(1) * time.Hour * -1), |
257 | 263 | HttpOnly: p.CookieHttpOnly, |
| 264 | + Secure: p.CookieSecure, |
| 265 | + Expires: time.Now().Add(time.Duration(1) * time.Hour * -1), |
258 | 266 | } |
259 | 267 | http.SetCookie(rw, cookie) |
260 | 268 | } |
261 | 269 |
|
262 | 270 | func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) { |
263 | 271 |
|
264 | | - domain := strings.Split(req.Host, ":")[0] // strip the port (if any) |
265 | | - if p.CookieDomain != "" && strings.HasSuffix(domain, p.CookieDomain) { |
| 272 | + domain := req.Host |
| 273 | + if h, _, err := net.SplitHostPort(domain); err == nil { |
| 274 | + domain = h |
| 275 | + } |
| 276 | + if p.CookieDomain != "" { |
| 277 | + if !strings.HasSuffix(domain, p.CookieDomain) { |
| 278 | + log.Printf("Warning: request host is %q but using configured cookie domain of %q", domain, p.CookieDomain) |
| 279 | + } |
266 | 280 | domain = p.CookieDomain |
267 | 281 | } |
268 | 282 | cookie := &http.Cookie{ |
@@ -444,11 +458,6 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { |
444 | 458 |
|
445 | 459 | if !ok { |
446 | 460 | user, ok = p.CheckBasicAuth(req) |
447 | | - // if we want to promote basic auth requests to cookie'd requests, we could do that here |
448 | | - // not sure that would be ideal in all circumstances though |
449 | | - // if ok { |
450 | | - // p.SetCookie(rw, req, user) |
451 | | - // } |
452 | 461 | } |
453 | 462 |
|
454 | 463 | if !ok { |
|
0 commit comments