Skip to content

Reject content writes addressed to a blob snapshot URL - #2895

Open
compiler-segfault (compiler-segfault) wants to merge 1 commit into
Azure:mainfrom
compiler-segfault:fix/snapshot-write-target
Open

compiler-segfault (compiler-segfault) wants to merge 1 commit into
Azure:mainfrom
compiler-segfault:fix/snapshot-write-target

Conversation

@compiler-segfault

@compiler-segfault compiler-segfault (compiler-segfault) commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

A content write whose request URL names a snapshot is applied to the base blob
instead of being rejected, so the emulator silently modifies the live blob that
the caller believes they are only reading.

Reproduction from #2854, on main (716539c):

  1. PUT /container/b with body 1
  2. PUT /container/b?comp=snapshot -> snapshot S
  3. PUT /container/b?snapshot=S with body 2

Before this change step 3 returns 201 and GET /container/b returns 2
while the snapshot still returns 1. Expected: the write is rejected and the
base blob keeps returning 1.

Root cause

?snapshot= is read by the download/properties/block-list paths, by delete (to
delete one snapshot), and by the lease handlers. No content-write handler reads
it, so the request falls through to the base blob.

Fix

Added validateWriteTargetIsNotSnapshot() in src/blob/utils/utils.ts and
call it at the entry of every content-writing handler. It returns 400 InvalidOperation with the Azure message Invalid operation against a blob snapshot. when the request URL carries a non-empty snapshot parameter, before
any content or extent is written.

Operations covered: Put Blob, Put Blob From URL, Put Block, Put Block From URL, Put Block List, Create Page Blob, Put Page, Clear Page,
Resize Page Blob, Set Page Blob Sequence Number, Create Append Blob,
Append Block, Append Block Seal, Copy Blob, Copy Blob From URL.

Property-level operations are unchanged: Azurite already supports snapshot
tags, and this change is scoped to operations that write blob content.

Tests

tests/blob/apis/blob.test.ts gains one test that addresses every write type
at a snapshot URL, asserts each request fails with 400 InvalidOperation, and
then verifies the base blob's content, length, and bytes are untouched.

  • npm run build
  • npx eslint "src/**/*.ts"
  • blob.test.ts: 140 passing
  • pageblob.test.ts, appendblob.test.ts, blockblob.test.ts: 188 passing

ChangeLog.md updated under Upcoming Release / Blob.

Supersedes #2863: that PR only guards Put Blob and has since gone stale and
conflicting with main; this one covers the remaining content-write paths.

Copilot AI balanced review requested due to automatic review settings November 8, 2026 12:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 8, 2026 12:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The snapshot query parameter is only read by the read, delete, and lease
handlers, so a content write that named a snapshot was treated as an ordinary
write to the base blob: a Put Blob to a snapshot URL returned 201 and replaced
the live blob.

Snapshots are immutable, so reject these requests with 400 InvalidOperation
("Invalid operation against a blob snapshot.") before any content is persisted.
Covers Put Blob, Put Blob From URL, Put Block, Put Block From URL, Put Block
List, Create Page Blob, Put Page, Clear Page, Resize Page Blob, Set Page Blob
Sequence Number, Create Append Blob, Append Block, Append Block Seal, and both
copy operations.

Fixes Azure#2854
Copilot AI balanced review requested due to automatic review settings November 8, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants