完善独立匿名密码恢复页面
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-16 13:06:15 +08:00
1 parent a8a65170d3
commit 581e70b2ca
10 files changed
+624 -46

No files matched your search

@@ -233,12 +233,12 @@ func requestMatchesHTTPSAuthority(r *http.Request, configured string) bool {
if r == nil {
return false
}
expectedHost, _, ok := configuredHTTPSAuthority(configured)
expectedHost, expectedPort, ok := configuredHTTPSAuthority(configured)
if !ok {
return false
}
requestHost, _, ok := normalizeAuthority(r.Host, "443")
return ok && requestHost == expectedHost
requestHost, requestPort, ok := normalizeAuthority(r.Host, "443")
return ok && requestHost == expectedHost && requestPort == expectedPort
}
func configuredHTTPSAuthority(value string) (string, string, bool) {
@@ -63,6 +63,34 @@ func TestPublicRecoveryPageIsServedOnlyFromMailDomain(t *testing.T) {
}
}
func TestPublicRecoveryPageRequiresConfiguredHTTPSPort(t *testing.T) {
configurePublicRecoveryRouteTest(t)
config.Instance.HttpsPort = 8443
handler, err := newPublicRecoveryHandler()
if err != nil {
t.Fatal(err)
}
allowed := httptest.NewRecorder()
handler.ServeHTTP(allowed, publicRecoveryRequest(http.MethodGet, "https://mx.example.com:8443/rest/"))
if allowed.Code != http.StatusOK {
t.Fatalf("configured HTTPS port returned %d, want %d", allowed.Code, http.StatusOK)
}
for _, target := range []string{
"https://mx.example.com/rest/",
"https://mx.example.com:9443/rest/",
} {
t.Run(target, func(t *testing.T) {
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, publicRecoveryRequest(http.MethodGet, target))
if recorder.Code != http.StatusNotFound {
t.Fatalf("unexpected recovery page status %d for %q", recorder.Code, target)
}
})
}
}
func TestPublicRecoveryLoginEntryRedirectsOnlyFromWebDomain(t *testing.T) {
configurePublicRecoveryRouteTest(t)
handler, err := newPublicRecoveryHandler()