Temporarily remove CSP header for flash
This commit is contained in:
parent
70275a734f
commit
0baba06ace
|
@ -54,7 +54,6 @@ func notFound(w http.ResponseWriter, r *http.Request, path string) error {
|
|||
func serverError(w http.ResponseWriter, r *http.Request, i interface{}) {
|
||||
startTime := time.Now()
|
||||
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
|
||||
nonce := types.GetNonce()
|
||||
|
@ -67,8 +66,7 @@ func serverError(w http.ResponseWriter, r *http.Request, i interface{}) {
|
|||
fmt.Printf("%s | ERROR: Invalid request for %s from %s\n",
|
||||
startTime.Format(logDate),
|
||||
r.URL.Path,
|
||||
r.RemoteAddr,
|
||||
)
|
||||
r.RemoteAddr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
30
cmd/files.go
30
cmd/files.go
|
@ -47,7 +47,8 @@ func humanReadableSize(bytes int) string {
|
|||
}
|
||||
|
||||
return fmt.Sprintf("%.1f %cB",
|
||||
float64(bytes)/float64(div), "kMGTPE"[exp])
|
||||
float64(bytes)/float64(div),
|
||||
"kMGTPE"[exp])
|
||||
}
|
||||
|
||||
func kill(path string, index *fileIndex) error {
|
||||
|
@ -136,7 +137,10 @@ func tryExtensions(splitPath *splitPath, formats types.Types) (string, error) {
|
|||
var path string
|
||||
|
||||
for extension := range formats {
|
||||
path = fmt.Sprintf("%s%s%s", splitPath.base, splitPath.number, extension)
|
||||
path = fmt.Sprintf("%s%s%s",
|
||||
splitPath.base,
|
||||
splitPath.number,
|
||||
extension)
|
||||
|
||||
exists, err := fileExists(path)
|
||||
if err != nil {
|
||||
|
@ -178,8 +182,7 @@ func pathIsValid(path string, paths []string) bool {
|
|||
case Verbose && !matchesPrefix:
|
||||
fmt.Printf("%s | ERROR: File outside specified path(s): %s\n",
|
||||
time.Now().Format(logDate),
|
||||
path,
|
||||
)
|
||||
path)
|
||||
|
||||
return false
|
||||
case !matchesPrefix:
|
||||
|
@ -423,8 +426,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
|
|||
filesMatched+filesSkipped,
|
||||
directoriesMatched,
|
||||
directoriesMatched+directoriesSkipped,
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
time.Since(startTime).Round(time.Microsecond))
|
||||
}
|
||||
|
||||
slices.Sort(list)
|
||||
|
@ -478,7 +480,9 @@ func pickFile(list []string) (string, error) {
|
|||
|
||||
func preparePath(prefix, path string) string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return fmt.Sprintf("%s/%s", prefix, filepath.ToSlash(path))
|
||||
return fmt.Sprintf("%s/%s",
|
||||
prefix,
|
||||
filepath.ToSlash(path))
|
||||
}
|
||||
|
||||
return prefix + path
|
||||
|
@ -530,8 +534,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
|
|||
if Verbose {
|
||||
fmt.Printf("%s | PATHS: Added %s\n",
|
||||
time.Now().Format(logDate),
|
||||
args[i],
|
||||
)
|
||||
args[i])
|
||||
}
|
||||
|
||||
paths = append(paths, path)
|
||||
|
@ -540,8 +543,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
|
|||
fmt.Printf("%s | PATHS: Added %s [resolved to %s]\n",
|
||||
time.Now().Format(logDate),
|
||||
args[i],
|
||||
path,
|
||||
)
|
||||
path)
|
||||
}
|
||||
|
||||
paths = append(paths, path)
|
||||
|
@ -549,16 +551,14 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
|
|||
if Verbose {
|
||||
fmt.Printf("%s | PATHS: Skipped %s (No supported files found)\n",
|
||||
time.Now().Format(logDate),
|
||||
args[i],
|
||||
)
|
||||
args[i])
|
||||
}
|
||||
case !pathMatches && !hasSupportedFiles:
|
||||
if Verbose {
|
||||
fmt.Printf("%s | PATHS: Skipped %s [resolved to %s] (No supported files found)\n",
|
||||
time.Now().Format(logDate),
|
||||
args[i],
|
||||
path,
|
||||
)
|
||||
path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,8 +251,7 @@ func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, enc
|
|||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: Index rebuild requested by %s\n",
|
||||
time.Now().Format(logDate),
|
||||
realIP(r),
|
||||
)
|
||||
realIP(r))
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Security-Policy", "default-src 'self';")
|
||||
|
@ -285,9 +284,7 @@ func registerIndexInterval(args []string, index *fileIndex, formats types.Types,
|
|||
select {
|
||||
case <-ticker.C:
|
||||
if Verbose {
|
||||
fmt.Printf("%s | INDEX: Started scheduled index rebuild\n",
|
||||
time.Now().Format(logDate),
|
||||
)
|
||||
fmt.Printf("%s | INDEX: Started scheduled index rebuild\n", time.Now().Format(logDate))
|
||||
}
|
||||
|
||||
rebuildIndex(args, index, formats, encoder, errorChannel)
|
||||
|
|
|
@ -40,8 +40,7 @@ func serveExtensions(formats types.Types, available bool, errorChannel chan<- er
|
|||
startTime.Format(logDate),
|
||||
humanReadableSize(written),
|
||||
realIP(r),
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
time.Since(startTime).Round(time.Microsecond))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +71,7 @@ func serveMediaTypes(formats types.Types, available bool, errorChannel chan<- er
|
|||
startTime.Format(logDate),
|
||||
humanReadableSize(written),
|
||||
realIP(r),
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
time.Since(startTime).Round(time.Microsecond))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
const (
|
||||
AllowedCharacters string = `^[A-z0-9.\-_]+$`
|
||||
ReleaseVersion string = "8.3.1"
|
||||
ReleaseVersion string = "8.4.0"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -617,8 +617,7 @@ func ServePage(args []string) error {
|
|||
fmt.Printf("%s | SERVE: Listening on http://%s%s/\n",
|
||||
time.Now().Format(logDate),
|
||||
listenHost,
|
||||
Prefix,
|
||||
)
|
||||
Prefix)
|
||||
}
|
||||
|
||||
err = srv.ListenAndServe()
|
||||
|
|
|
@ -15,11 +15,7 @@ import (
|
|||
type Format struct{}
|
||||
|
||||
func (t Format) CSP(w http.ResponseWriter) string {
|
||||
nonce := types.GetNonce()
|
||||
|
||||
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s'; script-src 'self' 'unsafe-inline'", nonce))
|
||||
|
||||
return nonce
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t Format) CSS() string {
|
||||
|
@ -38,8 +34,14 @@ func (t Format) Title(rootUrl, fileUri, filePath, fileName, prefix, mime string)
|
|||
func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime, nonce string) (string, error) {
|
||||
var html strings.Builder
|
||||
|
||||
html.WriteString(fmt.Sprintf(`<script nonce=%q src="https://unpkg.com/@ruffle-rs/ruffle"></script><script>window.RufflePlayer.config = {autoplay:"on"};</script><embed src="%s"></embed>`, nonce, fileUri))
|
||||
html.WriteString(fmt.Sprintf(`<br /><button onclick="window.location.href = '%s';">Next</button>`, rootUrl))
|
||||
html.WriteString(fmt.Sprintf(`<script nonce=%q src="https://unpkg.com/@ruffle-rs/ruffle"></script><script nonce=%q>window.RufflePlayer.config = {autoplay:"on"};</script><embed nonce=%qsrc="%s"></embed>`,
|
||||
nonce,
|
||||
nonce,
|
||||
nonce,
|
||||
fileUri),
|
||||
)
|
||||
html.WriteString(`<br /><button id="next">Next</button>`)
|
||||
html.WriteString(fmt.Sprintf(`<script nonce=%q>window.addEventListener("load", function () { document.getElementById("next").addEventListener("click", function () { window.location.href = '%s'; }) }); </script>`, nonce, rootUrl))
|
||||
|
||||
return html.String(), nil
|
||||
}
|
||||
|
|
|
@ -136,9 +136,11 @@ func ImageDimensions(path string) (*dimensions, error) {
|
|||
switch {
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
fmt.Printf("File %s does not exist\n", path)
|
||||
|
||||
return &dimensions{}, nil
|
||||
case err != nil:
|
||||
fmt.Printf("File %s open returned error: %s\n", path, err)
|
||||
|
||||
return &dimensions{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
@ -147,9 +149,11 @@ func ImageDimensions(path string) (*dimensions, error) {
|
|||
switch {
|
||||
case errors.Is(err, image.ErrFormat):
|
||||
fmt.Printf("File %s has invalid image format\n", path)
|
||||
|
||||
return &dimensions{width: 0, height: 0}, nil
|
||||
case err != nil:
|
||||
fmt.Printf("File %s decode returned error: %s\n", path, err)
|
||||
|
||||
return &dimensions{}, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue