vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Load the Prism worker from the static route
9a9e708c1def7250086e612cdee88e1ea12298ab · Keenan Nemetz · 21d ago · parent 7c02af12
Load the Prism worker from the static route The highlighting script asked for /static/prism-worker.js, but every browser asset is served under /-/static/. The request fell through to the HTML 404 page, so the browser refused the worker for its MIME type and every blob stayed plain. HTMX also compiles an hx-trigger filter with Function(), which script-src 'self' blocks. The two polling triggers used a visibility filter for that; drop the filter, pause the request in app.js while the tab is hidden, and turn eval off in the HTMX config so a future filter is caught instead of failing in production. Tests hold the worker to its route and the templates to trigger forms that do not need eval.
server/web/templates_test.go +46
| @@ -0,0 +1,46 @@ | |||
| 1 | package web | ||
| 2 | |||
| 3 | // HTMX compiles an hx-trigger filter, hx-on handler, or js: value with | ||
| 4 | // Function(), which the CSP forbids (script-src 'self'). A template that carries | ||
| 5 | // one makes the browser log an EvalError and leaves the trigger or value failing | ||
| 6 | // on the production instance, where tests rooted in the rendered HTML do not see | ||
| 7 | // a console. The conditions those filters used to express belong in app.js | ||
| 8 | // beside the request they guard. | ||
| 9 | |||
| 10 | import ( | ||
| 11 | "io/fs" | ||
| 12 | "regexp" | ||
| 13 | "strings" | ||
| 14 | "testing" | ||
| 15 | ) | ||
| 16 | |||
| 17 | var ( | ||
| 18 | htmxTrigger = regexp.MustCompile(`hx-trigger="([^"]*)"`) | ||
| 19 | htmxEval = regexp.MustCompile(`hx-(?:vals|headers)="(?:javascript:|js:)`) | ||
| 20 | ) | ||
| 21 | |||
| 22 | func TestTemplatesCarryNoHTMXEval(t *testing.T) { | ||
| 23 | t.Parallel() | ||
| 24 | files, err := fs.Glob(templateFS, "templates/*.html") | ||
| 25 | if err != nil { | ||
| 26 | t.Fatal(err) | ||
| 27 | } | ||
| 28 | for _, name := range files { | ||
| 29 | body, err := fs.ReadFile(templateFS, name) | ||
| 30 | if err != nil { | ||
| 31 | t.Fatal(err) | ||
| 32 | } | ||
| 33 | source := string(body) | ||
| 34 | for _, match := range htmxTrigger.FindAllStringSubmatch(source, -1) { | ||
| 35 | if strings.Contains(match[1], "[") { | ||
| 36 | t.Errorf("%s has an hx-trigger filter (%q), which HTMX evaluates with Function()", name, match[1]) | ||
| 37 | } | ||
| 38 | } | ||
| 39 | if strings.Contains(source, "hx-on:") || strings.Contains(source, "hx-on-") { | ||
| 40 | t.Errorf("%s has an hx-on handler, which HTMX evaluates with Function()", name) | ||
| 41 | } | ||
| 42 | if htmxEval.MatchString(source) { | ||
| 43 | t.Errorf("%s has a js: htmx value, which HTMX evaluates with Function()", name) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||