Skip to content

Commit

Permalink
Merge pull request #46 from ploxiln/cache_no_store
Browse files Browse the repository at this point in the history
prevent browser caching auth flow responses
  • Loading branch information
ploxiln authored May 6, 2020
2 parents 415ece6 + 953351b commit d92bf82
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func NewWebSocketOrRestReverseProxy(u *url.URL, opts *Options, auth hmacauth.Hma
return &UpstreamProxy{u.Host, proxy, wsProxy, auth}
}

func preventCaching(rw http.ResponseWriter) {
rw.Header().Set("Cache-Control", "no-store")
}

func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
serveMux := http.NewServeMux()
var auth hmacauth.HmacAuth
Expand Down Expand Up @@ -379,6 +383,7 @@ func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
}

func (p *OAuthProxy) PingPage(rw http.ResponseWriter) {
preventCaching(rw)
rw.WriteHeader(http.StatusOK)
fmt.Fprintf(rw, "OK")
}
Expand All @@ -399,6 +404,7 @@ func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
}

func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
preventCaching(rw)
p.ClearSessionCookie(rw, req)
rw.WriteHeader(code)

Expand Down Expand Up @@ -541,6 +547,7 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
p.ErrorPage(rw, 400, "Bad Request", err.Error())
return
}
preventCaching(rw)
session := &providers.SessionState{User: user}
p.SaveSession(rw, req, session)
http.Redirect(rw, req, redirect, 302)
Expand All @@ -554,11 +561,13 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
}

func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {
preventCaching(rw)
p.ClearSessionCookie(rw, req)
http.Redirect(rw, req, "/", 302)
}

func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
preventCaching(rw)
nonce, err := cookie.Nonce()
if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error())
Expand All @@ -576,6 +585,7 @@ func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
}

func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
preventCaching(rw)
remoteAddr := p.getRemoteAddr(req)

// finish the oauth cycle
Expand Down Expand Up @@ -637,6 +647,7 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
}

func (p *OAuthProxy) AuthenticateOnly(rw http.ResponseWriter, req *http.Request) {
preventCaching(rw)
status := p.Authenticate(rw, req)
if status == http.StatusAccepted {
rw.WriteHeader(http.StatusAccepted)
Expand Down

0 comments on commit d92bf82

Please sign in to comment.