CSRF Token Implementation for Plugins (#9192)

deleted test config

fix test config

Dont wipe the session token for plugins

Simplified Tokens; Generate CSRF for other sessions

Remove CSRF from Access Token; Remove Getter/Setter from Context

fix removed setter

remove getcsrf helper from plugin api

enforce csrf only for cookie auth
Этот коммит содержится в:
Daniel Schalla
2018-08-02 00:16:04 +02:00
коммит произвёл Christopher Speller
родитель 90e84d76ef
Коммит 2936dc87d0
10 изменённых файлов: 126 добавлений и 4 удалений

Просмотреть файл

@@ -135,6 +135,20 @@ func (me *Session) GetUserRoles() []string {
return strings.Fields(me.Roles)
}
func (me *Session) GenerateCSRF() string {
token := NewId()
me.AddProp("csrf", token)
return token
}
func (me *Session) GetCSRF() string {
if me.Props == nil {
return ""
}
return me.Props["csrf"]
}
func SessionsToJson(o []*Session) string {
if b, err := json.Marshal(o); err != nil {
return "[]"

Просмотреть файл

@@ -63,3 +63,18 @@ func TestSessionJson(t *testing.T) {
session.SetExpireInDays(10)
}
func TestSessionCSRF(t *testing.T) {
s := Session{}
token := s.GetCSRF()
assert.Empty(t, token)
token = s.GenerateCSRF()
assert.NotEmpty(t, token)
token2 := s.GetCSRF()
assert.NotEmpty(t, token2)
assert.Equal(t, token, token2)
}