n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
48.11k stars 7.44k forks source link

AuthorizationHeaderMalformed on a custom AWS HTTP request #10459

Open srdosramos opened 2 months ago

srdosramos commented 2 months ago

Bug Description

Issue: When creating a custom HTTP request to the AWS S3 endpoint, an error is encountered:

AuthorizationHeaderMalformed: The authorization header is malformed; the region 's3' is wrong; expecting 'us-east-1'us-east-1.

Details: Upon inspecting the error details, it was found that the authorization header is incorrect. Here is an example of the erroneous authorization header displayed in the error details:

"Authorization": "AWS4-HMAC-SHA256 Credential=AXXXXXXXXXXXXXXXXXLX/20240816/s3/s3/aws4_request, SignedHeaders=accept;content-type;host;x-amz-content-sha256;x-amz-copy-source;x-amz-date;x-amz-metadata-directive, Signature=f755fcae13c82b74d67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXd3"

In the authorization header, the service s3 is duplicated (/s3/s3/aws4_request) instead of specifying the region. It should be /us-east-1/s3/aws4_request.

Correct Example: The correct format for the authorization header should be as follows:

"Authorization": "AWS4-HMAC-SHA256 Credential=AXXXXXXXXXXXXXXXXXLX/20240816/us-east-1/s3/aws4_request, SignedHeaders=accept;content-type;host;x-amz-content-sha256;x-amz-copy-source;x-amz-date;x-amz-metadata-directive, Signature=f755fcae13c82b74d67XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXd3"

Fix the authorization header to include the appropriate region to resolve this issue.

To Reproduce

On a workflow:

  1. Add a HTTP Request node
  2. Choose the method PUT
  3. On the URL: point it to a bucket file https://**[bucket]**.s3.amazonaws.com/**[filepath]**
  4. Choose Authentication to Predefined Credential type
  5. Choose the Credential type to AWS
  6. Choose a AWS credential with the right permissions to call the S3 API
  7. Add the following headers: "x-amz-copy-source":"/[bucket]/[filepath]", "x-amz-metadata-directive":"REPLACE", "content-type": "text/html"

Expected behavior

The file on the url should change the content type to text/html

Operating System

Ubuntu 22.04

n8n Version

v1.54.4

Node.js Version

v20.15.0

Database

PostgreSQL

Execution mode

main (default)

Joffcom commented 2 months ago

Hey @srdosramos,

We have created an internal ticket to look into this which we will be tracking as "GHC-168"

Joffcom commented 2 months ago

Hey @srdosramos,

Quick update, I have taken a look and have moved this to our Nodes / Integrations team to resolve in a future release.