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

New Published Rules - federicobellini.session-cookie-samesitenone #3361

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions go/gorilla/security/audit/session-cookie-samesitenone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"net/http"
"github.com/gorilla/sessions"
)

var store = sessions.NewCookieStore([]byte(""))

func setSessionWithSameSiteNone(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
// ruleid: session-cookie-samesitenone
session.Options = &sessions.Options{
Path: "/",
MaxAge: 3600,
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteNoneMode,
}
session.Save(r, w)
}

func setSessionWithSameSiteStrict(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
// ok: session-cookie-samesitenone
session.Options = &sessions.Options{
Path: "/",
MaxAge: 3600,
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteStrictMode,
}
session.Save(r, w)
}

func main() {
http.HandleFunc("/set-none", setSessionWithSameSiteNone)
http.HandleFunc("/set-strict", setSessionWithSameSiteStrict)
http.ListenAndServe(":8080", nil)
}
36 changes: 36 additions & 0 deletions go/gorilla/security/audit/session-cookie-samesitenone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
rules:
- id: session-cookie-samesitenone
patterns:
- pattern-inside: |
&sessions.Options{
...,
SameSite: http.SameSiteNoneMode,
...,
}
- pattern: |
&sessions.Options{
...,
}
message: Found SameSiteNoneMode setting in Gorilla session options. Consider setting
SameSite to Lax, Strict or Default for enhanced security.
metadata:
cwe:
- 'CWE-1275: Sensitive Cookie with Improper SameSite Attribute'
owasp:
- A05:2021 - Security Misconfiguration
references:
- https://pkg.go.dev/github.com/gorilla/sessions#Options
category: security
technology:
- gorilla
confidence: MEDIUM
subcategory:
- audit
likelihood: LOW
impact: LOW
fix-regex:
regex: (SameSite\s*:\s+)http.SameSiteNoneMode
replacement: \1http.SameSiteDefaultMode
severity: WARNING
languages:
- go
Loading