Azure-sdk-for-js: Authorization problem when including a library

Created on 13 Aug 2020  Â·  5Comments  Â·  Source: Azure/azure-sdk-for-js

@azure/storage-blob - 12.2.0-preview.1
Operating system : Debian
nodejs : v12.16.1

Hi, I am facing a problem with azure storage authorization. It works well if I don't include a particular library https://github.com/pagarme/pagarme-js
If and only if I include the library above in the files I get the following error :

azure:core-http:info ServiceClient: using custom request policies
azure:storage-blob:info RetryPolicy: =====> Try=1 Primary
azure:storage-blob:info Request: {
  "streamResponseBody": false,
  "url": "https://versatyou.blob.core.windows.net/closet?restype=container",
  "method": "GET",
  "headers": {
    "_headersMap": {
      "x-ms-version": "2019-12-12",
      "user-agent": "azsdk-js-storageblob/12.2.0-preview.1 (NODE-VERSION v12.16.1; Linux 4.19.0-6-amd64)",
      "x-ms-client-request-id": "5638202a-9f54-4364-8c58-c5bb37b306d8"
    }
  },
  "withCredentials": false,
  "timeout": 0,
  "keepAlive": true,
  "requestId": "5638202a-9f54-4364-8c58-c5bb37b306d8"
}
azure:storage-blob:info Response status code: 200
azure:storage-blob:info Headers: {
  "_headersMap": {
    "content-length": "0",
    "last-modified": "Tue, 21 Apr 2020 03:38:19 GMT",
    "etag": "\"0x8D7E5A56F3C61E3\"",
    "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
    "x-ms-request-id": "c65f3bee-401e-0063-1587-71d2b4000000",
    "x-ms-client-request-id": "5638202a-9f54-4364-8c58-c5bb37b306d8",
    "x-ms-version": "2019-12-12",
    "x-ms-lease-status": "unlocked",
    "x-ms-lease-state": "available",
    "x-ms-has-immutability-policy": "false",
    "x-ms-has-legal-hold": "false",
    "x-ms-blob-public-access": "blob",
    "x-ms-default-encryption-scope": "$account-encryption-key",
    "x-ms-deny-encryption-scope-override": "false",
    "date": "Thu, 13 Aug 2020 15:36:41 GMT"
  }
}
azure:core-http:info ServiceClient: using custom request policies
azure:storage-blob:info RetryPolicy: =====> Try=1 Primary
azure:storage-blob:info Request: {
  "streamResponseBody": false,
  "url": "https://versatyou.blob.core.windows.net/closet/372-1597333001317.jpg",
  "method": "PUT",
  "headers": {
    "_headersMap": {
      "content-type": "application/octet-stream",
      "content-length": "47953",
      "x-ms-version": "2019-12-12",
      "x-ms-blob-type": "BlockBlob",
      "user-agent": "azsdk-js-storageblob/12.2.0-preview.1 (NODE-VERSION v12.16.1; Linux 4.19.0-6-amd64)",
      "x-ms-client-request-id": "844fb675-976f-4f45-a280-272c6429cc19"
    }
  },
  "withCredentials": false,
  "timeout": 0,
  "keepAlive": true,
  "requestId": "844fb675-976f-4f45-a280-272c6429cc19"
}
azure:storage-blob:info Response status code: 403
azure:storage-blob:info Headers: {
  "_headersMap": {
    "content-length": "777",
    "content-type": "application/xml",
    "server": "Microsoft-HTTPAPI/2.0",
    "x-ms-request-id": "c65f3c3e-401e-0063-5f87-71d2b4000000",
    "x-ms-error-code": "AuthenticationFailed",
    "date": "Thu, 13 Aug 2020 15:36:41 GMT"
  }
}
RestError: <?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.
RequestId:c65f3c3e-401e-0063-5f87-71d2b4000000
Time:2020-08-13T15:36:41.9145879Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request '/GQQJkZV5RJOrZsHeCXDRhomWgDQEvS74tBkEa8BPSU=' is not the same as any computed signature. Server used following string to sign: 'PUT




application/octet-stream






x-ms-blob-type:BlockBlob
x-ms-date:Thu, 13 Aug 2020 15:36:41 GMT
x-ms-version:2019-12-12
/versatyou/closet/372-1597333001317.jpg'.</AuthenticationErrorDetail></Error> 
 {
  "name": "RestError",
  "statusCode": 403,
  "request": {
    "streamResponseBody": false,
    "url": "https://versatyou.blob.core.windows.net/closet/372-1597333001317.jpg",
    "method": "PUT",
    "headers": {
      "_headersMap": {
        "content-type": "application/octet-stream",
        "x-ms-version": "REDACTED",
        "x-ms-blob-type": "REDACTED",
        "user-agent": "azsdk-js-storageblob/12.2.0-preview.1 (NODE-VERSION v12.16.1; Linux 4.19.0-6-amd64)",
        "x-ms-date": "REDACTED",
        "authorization": "REDACTED",
        "cookie": "REDACTED"
      }
    },
    "withCredentials": false,
    "timeout": 0,
    "keepAlive": true,
    "decompressResponse": false,
    "requestId": "844fb675-976f-4f45-a280-272c6429cc19"
  },
  "details": {
    "date": "2020-08-13T15:36:41.000Z",
    "errorCode": "AuthenticationFailed",
    "content-length": "777",
    "content-type": "application/xml",
    "server": "Microsoft-HTTPAPI/2.0",
    "message": "Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:c65f3c3e-401e-0063-5f87-71d2b4000000\nTime:2020-08-13T15:36:41.9145879Z",
    "Code": "AuthenticationFailed",
    "AuthenticationErrorDetail": "The MAC signature found in the HTTP request '/GQQJkZV5RJOrZsHeCXDRhomWgDQEvS74tBkEa8BPSU=' is not the same as any computed signature. Server used following string to sign: 'PUT\n\n\n\n\napplication/octet-stream\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-client-request-id:844fb675-976f-4f45-a280-272c6429cc19\nx-ms-date:Thu, 13 Aug 2020 15:36:41 GMT\nx-ms-version:2019-12-12\n/versatyou/closet/372-1597333001317.jpg'."
  },
  "message": "<?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:c65f3c3e-401e-0063-5f87-71d2b4000000\nTime:2020-08-13T15:36:41.9145879Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request '/GQQJkZV5RJOrZsHeCXDRhomWgDQEvS74tBkEa8BPSU=' is not the same as any computed signature. Server used following string to sign: 'PUT\n\n\n\n\napplication/octet-stream\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-client-request-id:844fb675-976f-4f45-a280-272c6429cc19\nx-ms-date:Thu, 13 Aug 2020 15:36:41 GMT\nx-ms-version:2019-12-12\n/versatyou/closet/372-1597333001317.jpg'.</AuthenticationErrorDetail></Error>"
}

I just have to include the library using require in my files, and stop working!
That behavior is weird. Javascript is supposed to be a memory-safe language, so adding a new library won't change anything.

I need to know is there some internal problems that might cause this.

Client Storage customer-reported needs-team-attention question

All 5 comments

Hi, @caotic123

Thanks for reaching us. This issue is similar to #9300, when library https://github.com/pagarme/pagarme-js is used, Content-Length header is not added when request is sent, per following log segment for Put blob:

'PUT\n\n\n\n\napplication/octet-stream\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-client-request-id:844fb675-976f-4f45-a280-272c6429cc19\nx-ms-date:Thu, 13 Aug 2020 15:36:41 GMT\nx-ms-version:2019-12-12\n/versatyou/closet/372-1597333001317.jpg'

The fix for #9300 has already been merged to master, and we'll update further when it's released.

Thanks,
Jiachen

Thank you @jiacfan.
However, I built the last version on the master and still getting the same error.

Hi, @caotic123

Are you building the latest code in master branch? Or using the latest npm package? As we've not yet released the fix, it's expected to repro the same issue in existing latest release. If you're building the latest code in master branch, would you share the request/response for the error?

Thanks,
Jiachen

I built the lastest code in the master branch, however, I still getting conflicts with the header. As a workaround, I just moved the import to some local context like :

  function then() {
   import {} from conflict_library;
   ....
}

Well, now it works.

Good to know the workaround works.

Thanks,
Jiachen

Was this page helpful?
0 / 5 - 0 ratings