-
Notifications
You must be signed in to change notification settings - Fork 95
[WIP] Update: Key-Pair auth data check #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/server/middleware/auth.ts
Outdated
if (data && req.method === "POST" && data !== hashRequestBody(req)) { | ||
error = "The request body has been tampered with."; | ||
throw error; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can only do this check when the request is of POST type, otherwise the req.body will come as empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we even need this check. If the developer hashes a request body and calls a GET endpoint, I think it's desirable (stricter) that the auth fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the POST
check as GET
spec doesn't support body as per the HTTP/1.1. Some web servers (Apache, Nginx & Traefik) drop the body param for GET request when forwarding the request. The spec doesn't forbid it, but the HTTP servers do drop it.
src/server/middleware/auth.ts
Outdated
@@ -278,6 +282,11 @@ const handleKeypairAuth = async ( | |||
throw error; | |||
} | |||
|
|||
if (data && req.method === "POST" && data !== hashRequestBody(req)) { | |||
error = "The request body has been tampered with."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error sounds scary when the dev may have just made a mistake. Let's make sure errors directly state the issue and optionally provide a way to fix it:
The request body does not match the hash in the access token. See: https://portal.thirdweb.com/engine/features/keypair-authentication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
can we tinyurl this?
PR-Codex overview
The focus of this PR is to enhance authentication middleware in the server by adding keypair authentication with body hashing validation.
Detailed summary
createHash
import for hashingonRequest
topreValidation
handleKeypairAuth
to include body hashing validationhashRequestBody
function to hash request body