Skip to content

Commit

Permalink
fix: bypass check for token & verify endpoints (#1785)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Allow requests to skip check for authorized email addresses for /token
and /verify endpoints

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.
  • Loading branch information
kangmingtay authored Oct 3, 2024
1 parent 2c13a7f commit 9ac2ea0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ func isIgnoreCaptchaRoute(req *http.Request) bool {

var emailLabelPattern = regexp.MustCompile("[+][^@]+@")

// we don't need to enforce the check on these endpoints since they don't send emails
var containsNonEmailSendingPath = regexp.MustCompile(`^/(admin|token|verify)`)

func (a *API) isValidAuthorizedEmail(w http.ResponseWriter, req *http.Request) (context.Context, error) {
ctx := req.Context()

// skip checking for authorized email addresses if it's an admin request
if strings.HasPrefix(req.URL.Path, "/admin") || req.Method == http.MethodGet || req.Method == http.MethodDelete {
if containsNonEmailSendingPath.MatchString(req.URL.Path) || req.Method == http.MethodGet || req.Method == http.MethodDelete {
return ctx, nil
}

Expand Down
14 changes: 14 additions & 0 deletions internal/api/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,20 @@ func (ts *MiddlewareTestSuite) TestIsValidAuthorizedEmail() {
"email": "test@example.com",
},
},
{
desc: "bypass check for token endpoint",
reqPath: "/token",
body: map[string]interface{}{
"email": "valid@example.com",
},
},
{
desc: "bypass check for verify endpoint",
reqPath: "/token",
body: map[string]interface{}{
"email": "valid@example.com",
},
},
{
desc: "bypass check if no email in request body",
reqPath: "/signup",
Expand Down

0 comments on commit 9ac2ea0

Please sign in to comment.