fix(envd/auth): move expiration check before ConstantTimeCompare to close timing oracle - #3562
Open
AdaAibaby wants to merge 1 commit into
Open
fix(envd/auth): move expiration check before ConstantTimeCompare to close timing oracle#3562AdaAibaby wants to merge 1 commit into
AdaAibaby wants to merge 1 commit into
Conversation
…lose timing oracle validateSigning checked HMAC first, then expiration. A correct-but-expired signature traversed both checks; an incorrect signature short-circuited at the HMAC step. The difference in response time is measurable and lets an attacker confirm a valid HMAC candidate without ever needing to produce a non-expired token, reducing brute-force cost for the file-signing key. Move the expiration gate before ConstantTimeCompare so expired requests are rejected before any HMAC work is done. Only non-expired requests now reach the timing-sensitive comparison, eliminating the oracle. Fixes: e2b-dev#3561
AdaAibaby
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
August 13, 2026 10:26
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #3561
validateSigninginpackages/envd/internal/api/auth.gochecked HMAC before signature expiration:ConstantTimeCompare→ returnConstantTimeCompare→ expiration check → returnAn attacker can time responses to confirm a valid HMAC candidate without producing a non-expired token, narrowing brute-force search significantly. The envd file-signing key is long-lived (tied to sandbox lifetime) and a forged signature grants arbitrary file read/write to any running sandbox.
Fix
Move expiration before HMAC comparison. Expired requests are rejected immediately; only non-expired requests reach the timing-sensitive
ConstantTimeCompare:No behaviour change for valid, non-expired requests. The ordering of error returns is preserved.
Changes
Single file,
packages/envd/internal/api/auth.go: swap the two blocks and update comments (+10/-7 lines, logic-only).