-
-
Notifications
You must be signed in to change notification settings - Fork 490
Description
Fiber version/commit
v2
Issue description
This recipe has a number of issues that are at best broken and teach bad practices; at worst are dangerous for users to follow as an implementation guide.
I believe this recipe should be recreated to follow standards, have clear documentation, and act securely.
-
The documentation for this recipe is incorrect and unsafely implements the JWT middleware causing it to be susceptible to hijacking/spoofing.
-
The user
GET
method is not protected, as is mentioned in the documentation, leading to being able to view other users' PII. -
Tokens are not invalidated after account deletion, allowing a user to continue accessing the API after deleting their account.
-
It additionally does not follow best practice standards for error checking or using magic numbers when constants are available in Go core.
e.g.
return c.Status(500).JSON(fiber.Map{"status": "error", "message": "Not valid user", "data": nil})
vs
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"status": "error", "message": "Not valid user", "data": nil})
Expected behavior
- Able to register by following the documentation
- Nil secret HS-265 JWTs should never be issued/valid
- Should not be able to view PII of other users
- JWT should be invalidated when an account is deleted
- Standards should be followed for error handling
Steps to reproduce
Spoofing:
- Follow instructions for the recipe, do not set a value for the
SECRET
environment variable - You will not be able to create a user on the first stage
- Instead send the POST request to the
/api/user
route for it to succeed - Make a second call to create a second user
- Call
api/auth/login
using the login details for the first user - Manually edit the content of the token using
jwt.io
or similar to set"user_id": 99999
- Use cURL to call
DELETE
on routeapi/user/2
- If no secret is set, this token will be valid and user 2 will be marked as deleted
PII access:
- Create multiple accounts as above
- Attempt to access the
/api/user/:id
route without a JWT - See that all details, including email and password hash are returned for any valid user ID
Deletion:
- Create an account following the above rectified steps
- Call the
DELETE
method against your user - A Error 500 response will be thrown with the following body (including mismatched error codes):
{
"data":{
"code":422,
"message":"Unprocessable Entity"
},
"message":"Review your input",
"status":"error"
}
- Include the undocumented body param and content type in the request
- Attempt to access a protected route
- The response will be successful as the JWT has not been invalidated on account deletion