For browser-based applications, it is recommended to pair the library's JWT XSRF check with Go 1.25+'s http.CrossOriginProtection.
While the library's JWT XSRF check handles API clients sending JWT-derived headers, http.CrossOriginProtection provides a primary defense at the HTTP layer by checking the Sec-Fetch-Site header (or Origin vs Host fallback). This protects against cross-origin state-changing requests and blocks subdomain attacks that SameSite=Lax might miss.
To use it, wrap your router with the http.CrossOriginProtection handler and configure trusted origins or bypass patterns for specific endpoints (like Apple Sign In).
csrf := http.NewCrossOriginProtection()
_ = csrf.AddTrustedOrigin("https://app.example.com") // for cross-origin SPAs
csrf.AddInsecureBypassPattern("POST /auth/apple/") // Apple Sign In uses form_post
mux := http.NewServeMux()
mux.Handle("/api/", authenticator.Auth(apiHandler))
log.Fatal(http.ListenAndServe(":8080", csrf.Handler(mux)))