mirror of https://github.com/gophish/gophish
pull/1557/merge
parent
07b46d226a
commit
a0e8c4a369
|
@ -2,8 +2,9 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
log "github.com/gophish/gophish/logger"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
log "github.com/gophish/gophish/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AdminServer represents the Admin server configuration details
|
// AdminServer represents the Admin server configuration details
|
||||||
|
@ -12,6 +13,7 @@ type AdminServer struct {
|
||||||
UseTLS bool `json:"use_tls"`
|
UseTLS bool `json:"use_tls"`
|
||||||
CertPath string `json:"cert_path"`
|
CertPath string `json:"cert_path"`
|
||||||
KeyPath string `json:"key_path"`
|
KeyPath string `json:"key_path"`
|
||||||
|
CSRFKey string `json:"csrf_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PhishServer represents the Phish server configuration details
|
// PhishServer represents the Phish server configuration details
|
||||||
|
|
|
@ -62,6 +62,7 @@ func TestLoadConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
expectedConfig.MigrationsPath = expectedConfig.MigrationsPath + expectedConfig.DBName
|
expectedConfig.MigrationsPath = expectedConfig.MigrationsPath + expectedConfig.DBName
|
||||||
expectedConfig.TestFlag = false
|
expectedConfig.TestFlag = false
|
||||||
|
expectedConfig.AdminConf.CSRFKey = ""
|
||||||
if !reflect.DeepEqual(expectedConfig, conf) {
|
if !reflect.DeepEqual(expectedConfig, conf) {
|
||||||
t.Fatalf("invalid config received. expected %#v got %#v", expectedConfig, conf)
|
t.Fatalf("invalid config received. expected %#v got %#v", expectedConfig, conf)
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,11 @@ func (as *AdminServer) registerRoutes() {
|
||||||
router.PathPrefix("/").Handler(http.FileServer(unindexed.Dir("./static/")))
|
router.PathPrefix("/").Handler(http.FileServer(unindexed.Dir("./static/")))
|
||||||
|
|
||||||
// Setup CSRF Protection
|
// Setup CSRF Protection
|
||||||
csrfHandler := csrf.Protect([]byte(util.GenerateSecureKey()),
|
csrfKey := []byte(as.config.CSRFKey)
|
||||||
|
if len(csrfKey) == 0 {
|
||||||
|
csrfKey = []byte(util.GenerateSecureKey())
|
||||||
|
}
|
||||||
|
csrfHandler := csrf.Protect(csrfKey,
|
||||||
csrf.FieldName("csrf_token"),
|
csrf.FieldName("csrf_token"),
|
||||||
csrf.Secure(as.config.UseTLS))
|
csrf.Secure(as.config.UseTLS))
|
||||||
adminHandler := csrfHandler(router)
|
adminHandler := csrfHandler(router)
|
||||||
|
|
Loading…
Reference in New Issue