Change nonce length to a constant

This commit is contained in:
Seednode 2024-01-30 13:27:45 -06:00
parent dbe3bbe0d6
commit 3814e10f20
9 changed files with 13 additions and 11 deletions

View File

@ -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))

View File

@ -17,7 +17,7 @@ import (
const (
AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "8.2.0"
ReleaseVersion string = "8.3.0"
)
var (

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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))

View File

@ -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 ""
}

View File

@ -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))