Skip to content

Commit

Permalink
fix: shift down require admin credentials check
Browse files Browse the repository at this point in the history
  • Loading branch information
joel authored and joel committed Feb 17, 2024
1 parent 3e57b61 commit 3e4a1c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions internal/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (a *API) requireAdmin(ctx context.Context, w http.ResponseWriter, r *http.R
// Find the administrative user
claims := getClaims(ctx)
if claims == nil {
fmt.Printf("[%s] %s %s %d %s\n", time.Now().Format("2006-01-02 15:04:05"), r.Method, r.RequestURI, http.StatusForbidden, "Invalid token")
return nil, unauthorizedError("Invalid token")
}

Expand All @@ -50,7 +49,6 @@ func (a *API) requireAdmin(ctx context.Context, w http.ResponseWriter, r *http.R
return withAdminUser(ctx, &models.User{Role: claims.Role, Email: storage.NullString(claims.Role)}), nil
}

fmt.Printf("[%s] %s %s %d %s\n", time.Now().Format("2006-01-02 15:04:05"), r.Method, r.RequestURI, http.StatusForbidden, "this token needs role 'supabase_admin' or 'service_role'")
return nil, unauthorizedError("User not allowed")
}

Expand Down
8 changes: 4 additions & 4 deletions internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ func (a *API) verifyCaptcha(w http.ResponseWriter, req *http.Request) (context.C
ctx := req.Context()
config := a.config

if !config.Security.Captcha.Enabled {
if !config.Security.Captcha.Enabled || isIgnoreCaptchaRoute(req) {
return ctx, nil
}

if _, err := a.requireAdminCredentials(w, req); err == nil {
// skip captcha validation if authorization header contains an admin role
return ctx, nil
}
if shouldIgnore := isIgnoreCaptchaRoute(req); shouldIgnore {
return ctx, nil
} else if err != nil {
return nil, err
}

verificationResult, err := security.VerifyRequest(req, strings.TrimSpace(config.Security.Captcha.Secret), config.Security.Captcha.Provider)
Expand Down

0 comments on commit 3e4a1c8

Please sign in to comment.