- /group ticket del: only the chat creator may remove a group registration - /node: always dial user-supplied node hosts through the netguard client; drop the https://127.0.0.1 prefix exemption - /app/@{username}: accept only username characters, render the greeting as text, add basic security headers Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package userpage
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func serve(path string) *httptest.ResponseRecorder {
|
|
r := mux.NewRouter()
|
|
r.HandleFunc("/app/@{username}", Service{}.UserWebAppHandler)
|
|
rec := httptest.NewRecorder()
|
|
r.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
|
|
return rec
|
|
}
|
|
|
|
func TestWebAppRejectsMarkupInUsername(t *testing.T) {
|
|
for _, p := range []string{
|
|
"/app/@%3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E",
|
|
"/app/@a%22%3Balert(1)%2F%2F",
|
|
"/app/@" + strings.Repeat("a", 65),
|
|
} {
|
|
rec := serve(p)
|
|
if rec.Code == http.StatusOK || strings.Contains(rec.Body.String(), "onerror") {
|
|
t.Errorf("%s: code %d, body %q", p, rec.Code, rec.Body.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWebAppRendersValidUsernameAsText(t *testing.T) {
|
|
rec := serve("/app/@alice_1")
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("code %d", rec.Code)
|
|
}
|
|
body := rec.Body.String()
|
|
if !strings.Contains(body, `textContent = "alice_1@ln.tips"`) || strings.Contains(body, "#greeting').innerHTML") {
|
|
t.Errorf("greeting is not set as text")
|
|
}
|
|
}
|