-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [CRITICAL] Fix Timing Leak in Secret Comparison #57
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,13 @@ adminRouter.use("*", async (c, next) => { | |||||||||||||||||||||||||||||
| throw new HTTPException(503, { message: "Admin API not configured." }); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| const provided = c.req.header("x-admin-key"); | ||||||||||||||||||||||||||||||
| if (!provided || !(await timingSafeEqual(expected, provided))) { | ||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||
| !provided || | ||||||||||||||||||||||||||||||
| !(await timingSafeEqual( | ||||||||||||||||||||||||||||||
| new TextEncoder().encode(expected), | ||||||||||||||||||||||||||||||
| new TextEncoder().encode(provided) | ||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly comparing secrets of different lengths using To prevent this length-based timing side-channel, hash both the expected and provided keys with SHA-256 before comparing them. This guarantees that both inputs to
Suggested change
|
||||||||||||||||||||||||||||||
| throw new HTTPException(401, { message: "Invalid admin key." }); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| await next(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
While
timingSafeEqualprevents timing attacks on the content of the secrets, comparing strings of different lengths directly still leaks the length of the secret becausetimingSafeEqualreturns early when the byte lengths of the inputs do not match.To completely eliminate length-based timing leaks, hash both values using SHA-256 before passing them to
timingSafeEqual. This ensures both inputs always have a fixed length of 32 bytes.