Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent browser caching auth flow responses #46

Merged
merged 1 commit into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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