Repository navigation
Reject Acquire Lease without a usable duration - #2896
Open
compiler-segfault (compiler-segfault) wants to merge 1 commit into
Open
compiler-segfault (compiler-segfault) wants to merge 1 commit into
compiler-segfault (compiler-segfault) wants to merge 1 commit into
Conversation
x-ms-lease-duration is mandatory for acquire, but a missing header parsed as undefined and slipped through the range check: undefined compares false against both bounds. The blob or container was then stored with leaseState Leased, no leaseDurationSeconds, and an invalid leaseExpireTime, so every later request failed with 500 and the resource stayed unusable until the emulator data was discarded. Require the header in both acquire handlers, returning 400 MissingRequiredHeader, and validate the duration in the lease state builders so a missing or non-integer value can never be persisted. Fixes Azure#2855
compiler-segfault (compiler-segfault)
force-pushed
the
fix/lease-duration-required
branch
from
November 8, 2026 12:32
4db751f to
81c1288
Compare
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
Acquire Leaseaccepts a request that omitsx-ms-lease-duration. The lease isstored in an unusable state and from then on every request that touches the blob
or container returns
500, so the emulated resource is bricked until theemulator data is discarded.
Reproduction from #2855, on
main(716539c):PUT /container/b(block blob)PUT /container/b?comp=leasewithx-ms-lease-action: acquireand nox-ms-lease-durationGET /container/bandGET /container?restype=container&comp=listBefore this change step 2 returns
201, and both reads in step 3 return500with
LeaseExpiredState:constructor() error, incoming leaseDurationSeconds undefinedin the log. The container and blob are stuck in that state.Root cause
options.durationisundefinedwhen the header is absent. The lease statebuilders validated the value with
undefined < 15andundefined > 60are bothfalse, so a missing durationpassed validation.
LeaseLeasedStatethen storedleaseState: LeasedwithleaseDurationSeconds: undefinedandleaseExpireTime: new Date(NaN). On thenext request the lease cannot be represented by any state, the constructor
throws a
RangeError, and the handler turns that into a500.Fix
BlobHandler.acquireLeaseandContainerHandler.acquireLeasenow require theheader and return
400 MissingRequiredHeaderwhen it is absent, matchingAzure Storage; both use a new
StorageErrorFactory.getMissingRequiredHeaderand an
X_MS_LEASE_DURATIONconstant.LeaseStateBase.validateLeaseDuration()rejects a duration that is not aninteger (including a missing value) before the lease state is built, so the
four
acquireimplementations share one check instead of four copies of theloose comparison.
Because validation happens before the lease is synced into the blob or
container record, a rejected acquire leaves no trace.
Tests
tests/blob/apis/blob.test.ts: acquire with no duration returns400 MissingRequiredHeader; the blob stays readable and listable; a well formedacquire right after still succeeds.
tests/blob/apis/container.test.ts: the same for container leases.npm run buildnpx eslint "src/**/*.ts"blob.test.ts+container.test.ts: 195 passing, 2 pendingChangeLog.mdupdated under Upcoming Release / Blob.Supersedes #2864: that PR handles blob leases only and has since gone stale and
conflicting with
main; this one covers container leases too and makes theinvalid value impossible to persist from any caller.