-
Notifications
You must be signed in to change notification settings - Fork 1
π‘οΈ Sentinel: [HIGH] Fix length timing oracle in token matching #481
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: develop
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 |
|---|---|---|
|
|
@@ -78,7 +78,15 @@ export async function handleAuthRoutes( | |
| const expected = normalizePairingCode(current); | ||
| const a = Buffer.from(expected, "utf8"); | ||
| const b = Buffer.from(provided, "utf8"); | ||
| if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) { | ||
| let match = true; | ||
| if (a.length !== b.length) { | ||
| const padded = Buffer.alloc(a.length); | ||
| b.copy(padded, 0, 0, Math.min(b.length, a.length)); | ||
| match = crypto.timingSafeEqual(a, padded) && false; | ||
| } else { | ||
| match = crypto.timingSafeEqual(a, b); | ||
| } | ||
|
Comment on lines
+81
to
+88
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. The current implementation still contains a timing oracle because of the const padded = Buffer.alloc(a.length);
b.copy(padded, 0, 0, Math.min(b.length, a.length));
const match = crypto.timingSafeEqual(a, padded) && a.length === b.length; |
||
| if (!match) { | ||
| error(res, "Invalid pairing code", 403); | ||
| return true; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4463,7 +4463,12 @@ export function resolveHyperscapeAuthorizationHeader( | |
| function tokenMatches(expected: string, provided: string): boolean { | ||
| const a = Buffer.from(expected, "utf8"); | ||
| const b = Buffer.from(provided, "utf8"); | ||
| if (a.length !== b.length) return false; | ||
| if (a.length !== b.length) { | ||
| // Pad to equal length to avoid length oracle | ||
| const padded = Buffer.alloc(a.length); | ||
| b.copy(padded, 0, 0, Math.min(b.length, a.length)); | ||
| return crypto.timingSafeEqual(a, padded) && false; | ||
| } | ||
| return crypto.timingSafeEqual(a, b); | ||
|
Comment on lines
+4466
to
4472
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. Similar to the change in const padded = Buffer.alloc(a.length);
b.copy(padded, 0, 0, Math.min(b.length, a.length));
return crypto.timingSafeEqual(a, padded) && a.length === b.length; |
||
| } | ||
|
|
||
|
|
||
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.
Security/Logic Issue:
The current implementation always sets
match = crypto.timingSafeEqual(a, padded) && false;when buffer lengths differ, which meansmatchis always false regardless of the timing-safe comparison. This defeats the purpose of using timing-safe comparison and may expose timing differences based on input length.Recommended Solution:
Always pad both buffers to the same length and use
crypto.timingSafeEqualdirectly, without forcibly setting the result to false. For example:This ensures consistent timing and proper comparison.