Adding option to disable CSRF protection (#248)

* Adding option to disable CSRF protection

This is useful at least for local development

cc/ @marwan-at-work

* using proper func name
This commit is contained in:
Aaron Schlesinger
2018-07-11 17:12:04 -07:00
committed by GitHub
parent 6459512234
commit d49e896d63
3 changed files with 25 additions and 4 deletions
+4 -2
View File
@@ -75,8 +75,10 @@ func App(config *AppConfig) *buffalo.App {
initializeTracing(app)
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
// Remove to disable this.
csrfMiddleware := csrf.New
app.Use(csrfMiddleware)
if env.EnableCSRFProtection() {
csrfMiddleware := csrf.New
app.Use(csrfMiddleware)
}
// TODO: parameterize the GoGet getter here.
//
+4 -2
View File
@@ -79,8 +79,10 @@ func App() (*buffalo.App, error) {
initializeTracing(app)
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
// Remove to disable this.
csrfMiddleware := csrf.New
app.Use(csrfMiddleware)
if env.EnableCSRFProtection() {
csrfMiddleware := csrf.New
app.Use(csrfMiddleware)
}
// Wraps each request in a transaction.
// c.Value("tx").(*pop.PopTransaction)
+17
View File
@@ -0,0 +1,17 @@
package env
import (
"strconv"
"github.com/gobuffalo/envy"
)
// EnableCSRFProtection determines whether to enable CSRF protection
func EnableCSRFProtection() bool {
boolStr := envy.Get("ATHENS_ENABLE_CSRF_PROTECTION", "false")
enable, err := strconv.ParseBool(boolStr)
if err != nil {
return false
}
return enable
}