Change nonce length to a constant
This commit is contained in:
parent
dbe3bbe0d6
commit
3814e10f20
|
@ -31,7 +31,7 @@ func notFound(w http.ResponseWriter, r *http.Request, path string) error {
|
|||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
@ -57,7 +57,7 @@ func serverError(w http.ResponseWriter, r *http.Request, i interface{}) {
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
const (
|
||||
AllowedCharacters string = `^[A-z0-9.\-_]+$`
|
||||
ReleaseVersion string = "8.2.0"
|
||||
ReleaseVersion string = "8.3.0"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
type Format struct{}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ type Format struct {
|
|||
}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';", nonce))
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
type Format struct{}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s'; script-src 'self' 'unsafe-inline'", nonce))
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ type Format struct {
|
|||
}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
type Format struct{}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const NonceLength = 6
|
||||
|
||||
var SupportedFormats = make(Types)
|
||||
|
||||
type Type interface {
|
||||
|
@ -136,8 +138,8 @@ func removeDuplicateStr(strSlice []string) []string {
|
|||
return list
|
||||
}
|
||||
|
||||
func GetNonce(length int) string {
|
||||
b := make([]byte, length)
|
||||
func GetNonce() string {
|
||||
b := make([]byte, NonceLength)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
type Format struct{}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce(6)
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s';", nonce))
|
||||
|
||||
|
|
Loading…
Reference in New Issue