-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: #618 Vulnerability: Individual can reset password of another ind…
…ividual
- Loading branch information
1 parent
c5a0165
commit dcb2121
Showing
3 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/bb-consent/api/internal/config" | ||
"github.com/bb-consent/api/internal/error_handler" | ||
"github.com/bb-consent/api/internal/token" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
// ValidateIndividualId Validates the individual id in path variable. | ||
func ValidateIndividualId() Middleware { | ||
|
||
// Create a new Middleware | ||
return func(f http.HandlerFunc) http.HandlerFunc { | ||
|
||
// Define the http.HandlerFunc | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
// To catch panic and recover the error | ||
// Once the error is recovered respond by | ||
// writing the error to HTTP response | ||
defer error_handler.HandleExit(w) | ||
headerType, _ := getAccessTokenFromHeader(w, r) | ||
|
||
if headerType == token.AuthorizationToken { | ||
// Get the path parameters from the request | ||
vars := mux.Vars(r) | ||
|
||
// Check if "individualId" is present in the path parameters | ||
if individualId, ok := vars[config.IndividualId]; ok { | ||
// Process the request with the individualId path parameter | ||
requestedIndividualId := token.GetUserID(r) | ||
|
||
if strings.TrimSpace(individualId) != strings.TrimSpace(requestedIndividualId) { | ||
m := "Unauthorized access;User doesn't have enough permissions;" | ||
error_handler.Exit(http.StatusBadRequest, m) | ||
} | ||
} | ||
} | ||
|
||
// Call the next middleware/handler in chain | ||
f(w, r) | ||
} | ||
} | ||
} |