-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinsecure-cookie.go
More file actions
48 lines (37 loc) · 907 Bytes
/
Copy pathinsecure-cookie.go
File metadata and controls
48 lines (37 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package session
import (
"log"
"fmt"
"net/http"
"govwa/util/config"
"github.com/gorilla/sessions"
)
type Self struct{}
func New() *Self {
return &Self{}
}
var store = sessions.NewCookieStore([]byte(config.Cfg.Sessionkey))
func (self *Self) SetSession(w http.ResponseWriter, r *http.Request, data map[string]string) {
session, err := store.Get(r, "govwa")
if err != nil {
log.Println(err.Error())
}
// ruleid: session-cookie-missing-secure
session.Options = &sessions.Options{
Path: "/",
MaxAge: 3600,
HttpOnly: false, //set to false for xss :)
Secure: true,
}
session.Values["govwa_session"] = true
//create new session to store on server side
if data != nil {
for key, value := range data {
session.Values[key] = value
}
}
err = session.Save(r, w) //safe session and send it to client as cookie
if err != nil {
log.Println(err.Error())
}
}