Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati
tollbooth.NewLimiter(api.config.RateLimitTokenRefresh/(60*5), &limiter.ExpirableOptions{
DefaultExpirationTTL: time.Hour,
}).SetBurst(30),
)).Post("/token", api.Token)
)).With(api.verifyCaptcha).Post("/token", api.Token)

r.With(api.limitHandler(
// Allow requests at the specified rate per 5 minutes.
Expand All @@ -136,7 +136,7 @@ func NewAPIWithVersion(ctx context.Context, globalConfig *conf.GlobalConfigurati
}).SetBurst(30),
)).Route("/verify", func(r *router) {
r.Get("/", api.Verify)
r.Post("/", api.Verify)
r.With(api.verifyCaptcha).Post("/", api.Verify)
})

r.With(api.requireAuthentication).Post("/logout", api.Logout)
Expand Down
6 changes: 3 additions & 3 deletions api/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (ts *MiddlewareTestSuite) TestVerifyCaptchaValid() {
"email": "test@example.com",
"password": "secret",
"gotrue_meta_security": map[string]interface{}{
"hcaptcha_token": HCaptchaResponse,
"captcha_token": HCaptchaResponse,
},
}))

Expand All @@ -75,7 +75,7 @@ func (ts *MiddlewareTestSuite) TestVerifyCaptchaValid() {
"email": "test@example.com",
"password": "secret",
"gotrue_meta_security": map[string]interface{}{
"hcaptcha_token": HCaptchaResponse,
"captcha_token": HCaptchaResponse,
},
}))

Expand Down Expand Up @@ -129,7 +129,7 @@ func (ts *MiddlewareTestSuite) TestVerifyCaptchaInvalid() {
"email": "test@example.com",
"password": "secret",
"gotrue_meta_security": map[string]interface{}{
"hcaptcha_token": HCaptchaResponse,
"captcha_token": HCaptchaResponse,
},
}))
req := httptest.NewRequest(http.MethodPost, "http://localhost", &buffer)
Expand Down
6 changes: 5 additions & 1 deletion security/hcaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type GotrueRequest struct {
}

type GotrueSecurity struct {
Token string `json:"hcaptcha_token"`
Token string `json:"captcha_token"`
}

type VerificationResponse struct {
Expand Down Expand Up @@ -56,6 +56,10 @@ func init() {
}

func VerifyRequest(r *http.Request, secretKey string) (VerificationResult, error) {
if r.FormValue("grant_type") == "refresh_token" {
// captcha shouldn't be enabled on requests to refresh the token
return SuccessfullyVerified, nil
}
res := GotrueRequest{}
bodyBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
Expand Down