Skip to content

Commit 735cfe5

Browse files
fioneraclaude
andcommitted
refactor: inline the captcha verify URL switch
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 92c1436 commit 735cfe5

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

validator_captcha.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ import (
1212
type captchaValidator struct {
1313
}
1414

15-
func captchaVerifyURL(t ValidationType) string {
16-
switch t {
17-
case ValidationTypeTurnstile:
18-
return "https://challenges.cloudflare.com/turnstile/v0/siteverify"
19-
case ValidationTypeHCaptcha:
20-
return "https://api.hcaptcha.com/siteverify"
21-
case ValidationTypeReCaptcha:
22-
return "https://www.google.com/recaptcha/api/siteverify"
23-
default:
24-
return ""
25-
}
26-
}
27-
2815
// Providers accept tokens of a few kilobytes; reCAPTCHA tokens are the
2916
// largest at around two to three kilobytes.
3017
const validatorCaptchaMaxTokenLength = 8 << 10
@@ -82,9 +69,18 @@ func (captchaValidator) isValid(b *Berghain, req *ValidatorRequest, _ *Validator
8269

8370
lc := b.LevelConfig(req.Identifier.Level)
8471

72+
// All three providers implement the same siteverify contract:
73+
// hCaptcha and Turnstile clone the reCAPTCHA API on purpose.
8574
verifyURL := lc.CaptchaVerifyURL
8675
if verifyURL == "" {
87-
verifyURL = captchaVerifyURL(lc.Type)
76+
switch lc.Type {
77+
case ValidationTypeTurnstile:
78+
verifyURL = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
79+
case ValidationTypeHCaptcha:
80+
verifyURL = "https://api.hcaptcha.com/siteverify"
81+
case ValidationTypeReCaptcha:
82+
verifyURL = "https://www.google.com/recaptcha/api/siteverify"
83+
}
8884
}
8985

9086
form := url.Values{

0 commit comments

Comments
 (0)