Skip to content
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

Content-Length isn't sent for default node http client #8903

Closed
1 task
Nurchik opened this issue May 13, 2020 · 9 comments
Closed
1 task

Content-Length isn't sent for default node http client #8903

Nurchik opened this issue May 13, 2020 · 9 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@Nurchik
Copy link

Nurchik commented May 13, 2020

Describe the bug
Because of the workaround for bug with axios axios/axios#2107 when we are:

  • using the SharedKeyCredential for interacting with the Azure Blob Storage especially on blob upload operation (Put Blob in terms of the REST API)
  • uploading Buffer or String as body

the Content-Length header gets removed from the headers of the request causing MAC signature mismatch. This happens because the local signature calculation is performed before the header removal here and at the server this field is absent.

To Reproduce
Steps to reproduce the behavior:

  1. Create any client for storage blob (BlobServiceClient, BlockBlobClient, etc.) with StorageSharedKeyCredential as credential
  2. upload Buffer blob

Expected behavior
Successful blob upload

Error Response

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>AuthenticationFailed</Code>
    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:00000000-0000-0000-0000-000000000000\nTime:2020-05-13T16:23:38.3682050Z</Message>
    <AuthenticationErrorDetail>The MAC signature found in the HTTP request 'QDv3EVRyiJiAgOT9GWtWC7VBITLvCEasKoTd3xai4+4=' is not the same as any computed signature. Server used following string to sign: 'PUT ...'.</AuthenticationErrorDetail>
</Error>

Code snippet to reproduce

const { StorageSharedKeyCredential, BlockBlobClient } = require("@azure/storage-blob");
const credentials = new StorageSharedKeyCredential(<account>, <storage key>);
const blob = new BlockBlobClient('https://<account>.blob.core.windows.net/<container>/report.txt', credentials);
const data = Buffer.from('test_string', 'utf-8')
blob.upload(data, Buffer.byteLength(data, 'utf-8'))
    .then(res => console.log('success ', res))
    .catch(err => console.error(err));
@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 13, 2020
@jeremymeng jeremymeng added Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files) labels May 13, 2020
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label May 13, 2020
@ljian3377
Copy link
Member

Sorry, I can not reproduce the issue with the snippet you provided. If you are using the SDK's default http client, it shouldn't have failed as node-fetch will add the 'Content-Length' header back.
https://github.com/node-fetch/node-fetch/blob/0936a9af0a049eb05897779f3f0df6b903a95d60/src/request.js#L237

Also we have plenty of tests covering this scenario.
So what we are missing here? Could it be some issue with you account key?

@thesiti92
Copy link

I think im having the same issue. I can upload a string to blob storage fine, but when i try to upload a buffer or a stream something breaks and i get this Auth error. A bug in content length headers could be the culprit.

@ljian3377
Copy link
Member

@thesiti92 @Nurchik
I really want to help. But I just can't recreate this. Tried with the snippet given by you and turned on the logger with

import { setLogLevel } from "@azure/logger";
setLogLevel("info");

It succeeded and from the log we can see that content length was set correctly.

azure:storage-blob:info Request: {
  "streamResponseBody": false,
  "url": "***",
  "method": "PUT",
  "headers": {
    "_headersMap": {
      "content-type": "application/octet-stream",
      "content-length": "11",
      "x-ms-version": "2019-07-07",
      "x-ms-blob-type": "BlockBlob",
      "user-agent": "azsdk-js-storageblob/12.1.1 (NODE-VERSION v12.13.0; Windows_NT 10.0.18362)",
      "x-ms-client-request-id": "1e6fd9dc-b17e-4ca4-9e2e-0cc188cc4b28"
    }
  },
  "withCredentials": false,
  "timeout": 0,
  "keepAlive": true,
  "requestId": "1e6fd9dc-b17e-4ca4-9e2e-0cc188cc4b28"
}
azure:storage-blob:info Response status code: 201
...

Also as I mentioned, we have plenty of test cases covering the buffer uploading scenario.
So could you please turn on the log as I did and provide the log here if you can recreate it so we can further investigate this?

@thesiti92
Copy link

ok will do. im not exactly sure if my issue is related to content-length, but i'll post here after and give you more info. Can make a new issue if need be. Thanks for the quick response!

@thesiti92
Copy link

ok the issue was not to do with content length, but something is messing up the HMAC authentication, not sure if its you guys or me.

@thesiti92
Copy link

Opened a new issue #9300

@ljian3377
Copy link
Member

ljian3377 commented Jun 10, 2020

Nice catch on the CONTENT_LENGTH workaround.
We can remove it as we do not use axio now.

@ljian3377 ljian3377 removed the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Jul 15, 2020
@ljian3377 ljian3377 added this to the [2020] August milestone Jul 15, 2020
@XiaoningLiu XiaoningLiu assigned ljian3377 and unassigned XiaoningLiu Jul 15, 2020
@ramya-rao-a ramya-rao-a added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jul 20, 2020
@Petermarcu Petermarcu added the Service Attention This issue is responsible by Azure service team. label Jul 29, 2020
@ghost
Copy link

ghost commented Jul 29, 2020

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@ljian3377 ljian3377 assigned jiacfan and unassigned ljian3377 Aug 17, 2020
@ljian3377 ljian3377 modified the milestones: [2020] September, Backlog Sep 9, 2020
@jiacfan
Copy link
Member

jiacfan commented Sep 9, 2020

Close as fix released.

@jiacfan jiacfan closed this as completed Sep 9, 2020
@xirzec xirzec removed this from the Backlog milestone May 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

9 participants