-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Storage] Blob Batch Inner-Header CRLF Injection Bugfix #50403
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
Merged
Isabelle (ibrandes)
merged 3 commits into
Azure:main
from
ibrandes:bugfix/storage/batchCRLFInjection
Sep 13, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
136 changes: 136 additions & 0 deletions
136
...-blob-batch/src/test/java/com/azure/storage/blob/batch/BlobBatchHeaderInjectionTests.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.storage.blob.batch; | ||
|
|
||
| import com.azure.core.http.HttpHeaderName; | ||
| import com.azure.core.http.HttpMethod; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.storage.blob.models.BlobRequestConditions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Collection; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * Regression tests for Blob Batch inner-header CRLF injection. | ||
| * | ||
| * <p>Inner request header names and values are serialized into the multipart batch body. Carriage return / line feed | ||
| * characters must be rejected on both the name and value so an attacker cannot terminate the intended header and inject | ||
| * a second Azure Storage operation-control header (such as {@code x-ms-delete-snapshots}).</p> | ||
| * | ||
| * <p>The header-<em>value</em> boundary is reachable through the public | ||
| * {@link BlobRequestConditions#setTagsConditions(String)} API. The header-<em>name</em> boundary is reachable by any | ||
| * pipeline policy that calls {@code HttpRequest#setHeader} with an arbitrary name, so it is exercised directly against | ||
| * the serializer.</p> | ||
| */ | ||
| public class BlobBatchHeaderInjectionTests extends BlobBatchTestBase { | ||
|
|
||
| private static final String BLOB_URL = "https://account.blob.core.windows.net/victim/target"; | ||
|
|
||
| private BlobBatchClient batchClient; | ||
|
|
||
| @Override | ||
| public void beforeTest() { | ||
| super.beforeTest(); | ||
| batchClient = new BlobBatchClientBuilder(primaryBlobServiceAsyncClient).buildClient(); | ||
| } | ||
|
|
||
| private static String serializeBody(BlobBatch batch) { | ||
| // prepareBlobBatchSubmission builds the batch body without sending a network request, so this exercises the | ||
| // serialization path (including inner-header validation) offline. | ||
| return serializeBody(batch.prepareBlobBatchSubmission().block()); | ||
| } | ||
|
|
||
| private static String serializeBody(BlobBatchOperationInfo info) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| Collection<ByteBuffer> body = info.getBody(); | ||
| for (ByteBuffer buffer : body) { | ||
| byte[] bytes = new byte[buffer.remaining()]; | ||
| buffer.duplicate().get(bytes); | ||
| sb.append(new String(bytes, StandardCharsets.UTF_8)); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| private static int countInjectedDeleteHeaders(String body) { | ||
| int count = 0; | ||
| for (String line : body.split("\r\n")) { | ||
| if ("x-ms-delete-snapshots: include".equalsIgnoreCase(line)) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| // --- Header value boundary (reachable via the public setTagsConditions API) --- | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource( | ||
| strings = { | ||
| "\"owner\" = 'attacker'\r\nx-ms-delete-snapshots: include", // CRLF | ||
| "\"owner\" = 'attacker'\rx-ms-delete-snapshots: include", // lone CR | ||
| "\"owner\" = 'attacker'\nx-ms-delete-snapshots: include" // lone LF | ||
| }) | ||
| public void lineBreakInTagsConditionIsRejected(String maliciousCondition) { | ||
| BlobBatch batch = batchClient.getBlobBatch(); | ||
| // deleteOptions is intentionally null - the application did NOT authorize snapshot deletion. | ||
| batch.deleteBlob("victim", "target", null, new BlobRequestConditions().setTagsConditions(maliciousCondition)); | ||
|
|
||
| // The line-break-bearing value must be rejected before it is serialized into the batch body. | ||
| assertThrows(IllegalArgumentException.class, () -> batch.prepareBlobBatchSubmission().block()); | ||
| } | ||
|
|
||
| @Test | ||
| public void cleanTagsConditionIsPreserved() { | ||
| BlobBatch batch = batchClient.getBlobBatch(); | ||
| batch.deleteBlob("victim", "target", null, | ||
| new BlobRequestConditions().setTagsConditions("\"owner\" = 'owner'")); | ||
|
|
||
| String body = serializeBody(batch); | ||
|
|
||
| assertEquals(0, countInjectedDeleteHeaders(body)); | ||
| assertTrue(body.contains("x-ms-if-tags: \"owner\" = 'owner'"), | ||
| "Clean tag condition header should be preserved intact"); | ||
| } | ||
|
|
||
| // --- Header name boundary (reachable by any policy that sets an arbitrary header name) --- | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource( | ||
| strings = { | ||
| "x-ms-inject\r\nx-ms-delete-snapshots", // CRLF | ||
| "x-ms-inject\rx-ms-delete-snapshots", // lone CR | ||
| "x-ms-inject\nx-ms-delete-snapshots" // lone LF | ||
| }) | ||
| public void lineBreakInHeaderNameIsRejected(String maliciousHeaderName) { | ||
| HttpRequest request = new HttpRequest(HttpMethod.DELETE, BLOB_URL); | ||
| request.setHeader(HttpHeaderName.fromString(maliciousHeaderName), "include"); | ||
|
|
||
| BlobBatchOperationInfo info = new BlobBatchOperationInfo(); | ||
| assertThrows(IllegalArgumentException.class, | ||
| () -> info.addBatchOperation(new BlobBatchOperationResponse<Void>(202), request)); | ||
| } | ||
|
|
||
| @Test | ||
| public void cleanHeaderNameIsPreserved() { | ||
| HttpRequest request = new HttpRequest(HttpMethod.DELETE, BLOB_URL); | ||
| request.setHeader(HttpHeaderName.fromString("x-ms-clean-header"), "clean-value"); | ||
|
|
||
| BlobBatchOperationInfo info = new BlobBatchOperationInfo(); | ||
| info.addBatchOperation(new BlobBatchOperationResponse<Void>(202), request); | ||
|
|
||
| String body = serializeBody(info); | ||
|
|
||
| assertEquals(0, countInjectedDeleteHeaders(body)); | ||
| assertTrue(body.contains("x-ms-clean-header: clean-value"), | ||
| "Clean header name and value should be preserved intact"); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.