From e52b7e69153f01989edb726a71b11ad4a31c59c9 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Wed, 8 Jul 2026 09:28:54 +0100 Subject: [PATCH] fix: CSRF extraction looks for specific zoraxy.csrf.Token --- tools/register-certs/main.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/tools/register-certs/main.go b/tools/register-certs/main.go index 766e142..95ec9e2 100644 --- a/tools/register-certs/main.go +++ b/tools/register-certs/main.go @@ -35,8 +35,7 @@ func main() { body, _ := io.ReadAll(resp.Body) resp.Body.Close() - re := regexp.MustCompile(`content="([^"]+)"`) - csrf := extractCSRF(string(body), re) + csrf := extractCSRF(string(body)) if csrf == "" { fmt.Fprintf(os.Stderr, "FAIL: could not extract CSRF token\n") os.Exit(1) @@ -106,7 +105,7 @@ func main() { } b, _ := io.ReadAll(resp.Body) resp.Body.Close() - csrf = extractCSRF(string(b), re) + csrf = extractCSRF(string(b)) if csrf == "" { fmt.Printf("WARN: %s no CSRF token\n", domain) continue @@ -138,21 +137,16 @@ func main() { } } -func extractCSRF(html string, re *regexp.Regexp) string { - match := re.FindAllStringSubmatch(html, -1) - for _, m := range match { - if len(m) > 1 && len(m[1]) > 20 { - return m[1] - } - } - // Try looking for the specific zoraxy.csrf.Token pattern +func extractCSRF(html string) string { idx := strings.Index(html, "zoraxy.csrf.Token") - if idx >= 0 { - sub := html[idx:] - m := re.FindStringSubmatch(sub) - if len(m) > 1 { - return m[1] - } + if idx < 0 { + return "" + } + sub := html[idx:] + re := regexp.MustCompile(`content="([^"]+)"`) + m := re.FindStringSubmatch(sub) + if len(m) > 1 { + return m[1] } return "" }