2026-04-17 05:46:44 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TestPingPageEscapesQuery asserts hostile query values cannot break out of
|
|
|
|
|
// the input's value attribute. elem-go does not escape attribute values, so
|
|
|
|
|
// the template must escape before rendering.
|
|
|
|
|
func TestPingPageEscapesQuery(t *testing.T) {
|
|
|
|
|
payloads := []string{
|
|
|
|
|
`" autofocus onfocus=alert(1) x="`,
|
|
|
|
|
`"><script>alert(1)</script>`,
|
|
|
|
|
`<img src=x onerror=alert(1)>`,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, p := range payloads {
|
|
|
|
|
t.Run(p, func(t *testing.T) {
|
|
|
|
|
out := PingPage(p, nil, nil).Render()
|
|
|
|
|
if strings.Contains(out, p) {
|
2026-04-29 14:41:37 +00:00
|
|
|
t.Fatalf("payload rendered without escaping: %q", p)
|
2026-04-17 05:46:44 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|