summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2025-10-13 00:47:36 +0900
committerhaturatu <taro@eyes4you.org>2025-10-13 00:47:36 +0900
commit67348df4105ba4f54919bbe117f652d751397c05 (patch)
tree24bccb440958d5329c30e4693e23c30fab422b7c
parent5fde794315efd7c8146e7b69b9e7d05132a2e3df (diff)
a
-rw-r--r--cmd/server/main.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go
index 4f0d30f..b89362b 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -186,10 +186,19 @@ func main() {
// In production, you should set csrf.Secure(true).
// You can use an environment variable to control this setting.
csrfOptions := []csrf.Option{
- csrf.Secure(true), // Set to true in production
+ csrf.Secure(os.Getenv("ENV") == "production"),
csrf.Path("/"),
}
+ sameSiteMode := csrf.SameSiteLaxMode
+ switch strings.ToLower(os.Getenv("CSRF_SAME_SITE")) {
+ case "strict":
+ sameSiteMode = csrf.SameSiteStrictMode
+ case "none":
+ sameSiteMode = csrf.SameSiteNoneMode
+ }
+ csrfOptions = append(csrfOptions, csrf.SameSite(sameSiteMode))
+
trustedOrigins := os.Getenv("CSRF_TRUSTED_ORIGINS")
if trustedOrigins != "" {
origins := strings.Split(trustedOrigins, ",")