aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenri Vasserman <henv@hot.ee>2025-03-31 22:09:29 +0300
committerXe Iaso <me@xeiaso.net>2025-03-31 17:44:11 -0400
commit71e6b697b8a74a3928ade45476725866d9312814 (patch)
treeaf6385d4599010a4c9881c6e53d8317a16d90f7a
parenta3c026977ff853f800b2ab353fb5d5304227a370 (diff)
downloadanubis-71e6b697b8a74a3928ade45476725866d9312814.tar.xz
anubis-71e6b697b8a74a3928ade45476725866d9312814.zip
cmd/anubis actually check the result with the correct difficulty
Signed-off-by: Xe Iaso <me@xeiaso.net>
-rw-r--r--lib/anubis.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/anubis.go b/lib/anubis.go
index 83e04dd..026f912 100644
--- a/lib/anubis.go
+++ b/lib/anubis.go
@@ -145,14 +145,13 @@ func New(opts Options) (*Server, error) {
}
type Server struct {
- mux *http.ServeMux
- next http.Handler
- priv ed25519.PrivateKey
- pub ed25519.PublicKey
- policy *policy.ParsedConfig
- opts Options
- DNSBLCache *decaymap.Impl[string, dnsbl.DroneBLResponse]
- ChallengeDifficulty int
+ mux *http.ServeMux
+ next http.Handler
+ priv ed25519.PrivateKey
+ pub ed25519.PublicKey
+ policy *policy.ParsedConfig
+ opts Options
+ DNSBLCache *decaymap.Impl[string, dnsbl.DroneBLResponse]
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -428,9 +427,9 @@ func (s *Server) PassChallenge(w http.ResponseWriter, r *http.Request) {
}
// compare the leading zeroes
- if !strings.HasPrefix(response, strings.Repeat("0", s.ChallengeDifficulty)) {
+ if !strings.HasPrefix(response, strings.Repeat("0", rule.Challenge.Difficulty)) {
s.ClearCookie(w)
- lg.Debug("difficulty check failed", "response", response, "difficulty", s.ChallengeDifficulty)
+ lg.Debug("difficulty check failed", "response", response, "difficulty", rule.Challenge.Difficulty)
templ.Handler(web.Base("Oh noes!", web.ErrorPage("invalid response")), templ.WithStatus(http.StatusForbidden)).ServeHTTP(w, r)
failedValidations.Inc()
return