fix(challenge/preact): ensure that the client waits as long as it needs to

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2025-08-29 19:12:38 +00:00
parent 9557442294
commit f2a60fedcc
2 changed files with 7 additions and 2 deletions

View File

@@ -34,8 +34,6 @@ const App = () => {
setPassed(true);
}, state.difficulty * 100);
console.log(challenge);
return () => clearTimeout(timer);
}, [challenge]);

View File

@@ -8,6 +8,7 @@ import (
"io"
"log/slog"
"net/http"
"time"
"github.com/TecharoHQ/anubis"
"github.com/TecharoHQ/anubis/internal"
@@ -56,6 +57,12 @@ func (i *impl) Issue(r *http.Request, lg *slog.Logger, in *challenge.IssueInput)
}
func (i *impl) Validate(r *http.Request, lg *slog.Logger, in *challenge.ValidateInput) error {
wantTime := in.Challenge.IssuedAt.Add(time.Duration(in.Rule.Challenge.Difficulty) * 95 * time.Millisecond)
if time.Now().Before(wantTime) {
return challenge.NewError("validate", "insufficent time", fmt.Errorf("%w: wanted user to wait until at least %s", wantTime.Format(time.RFC3339)))
}
got := r.FormValue("result")
want := internal.SHA256sum(in.Challenge.RandomData)