Skip to content

Commit

Permalink
feat(middleware): Add secure headers middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-welsch committed Feb 16, 2023
1 parent a2a0d8e commit 103b8ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## To be Released

* feat(middleware): add a middleware to reject HTTP request
* feat(middleware): Add secure headers middleware

## v1.7.0

Expand Down
15 changes: 15 additions & 0 deletions secure_headers_middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package handlers

import (
"net/http"
)

// Source: https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html#security-headers
func SecureHeadersMiddleware(next HandlerFunc) HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, vars map[string]string) error {
w.Header().Set("Content-Security-Policy", "frame-ancestors 'none'")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "DENY")
return next(w, r, vars)
}
}

0 comments on commit 103b8ed

Please sign in to comment.