Skip to content

Commit

Permalink
Set strict defaults for CSRF
Browse files Browse the repository at this point in the history
  • Loading branch information
feedmeapples committed May 19, 2022
1 parent 040e217 commit eb3d2b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/routes/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func authenticateCb(ctx context.Context, config *oauth2.Config, provider *oidc.P
Path: "/",
MaxAge: 7 * 24 * int(time.Hour.Seconds()),
HttpOnly: true,
SameSite: http.SameSiteNoneMode,
SameSite: http.SameSiteStrictMode,
Secure: true,
}
sess.Values["access-token"] = &user.OAuth2Token.AccessToken
Expand Down Expand Up @@ -175,7 +175,7 @@ func logout(c echo.Context) error {
Path: "/",
MaxAge: -1,
HttpOnly: true,
SameSite: http.SameSiteNoneMode,
SameSite: http.SameSiteStrictMode,
Secure: true,
}
sess.Save(c.Request(), c.Response())
Expand Down
6 changes: 5 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package server
import (
"embed"
"fmt"
"net/http"

"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
Expand Down Expand Up @@ -85,7 +86,10 @@ func NewServer(opts ...server_options.ServerOption) *Server {
}))
e.Use(middleware.Secure())
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
CookiePath: "/",
CookiePath: "/",
CookieHTTPOnly: true,
CookieSameSite: http.SameSiteStrictMode,
CookieSecure: true,
}))
e.Use(session.Middleware(sessions.NewCookieStore(
securecookie.GenerateRandomKey(32),
Expand Down

0 comments on commit eb3d2b3

Please sign in to comment.