Skip to content

Commit

Permalink
fix: do not sign content-type in s3-request-presigner
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Mar 19, 2020
1 parent 22900d4 commit d26a90b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions packages/s3-request-presigner/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,23 @@ describe("s3 presigner", () => {
});
expect(minimalRequest).toMatchObject(originalRequest);
});

it("should not sign content-type header", async () => {
const signer = new S3RequestPresigner(s3ResolvedConfig);
const requestWithContentTypeHeader = {
...minimalRequest,
headers: {
...minimalRequest.headers,
"Content-Type": "application/octet-stream"
}
};
const signed = await signer.presignRequest(
requestWithContentTypeHeader,
expiration,
presigningOptions
);
expect(signed.query).toMatchObject({
[SIGNED_HEADERS_QUERY_PARAM]: HOST_HEADER
});
});
});
8 changes: 6 additions & 2 deletions packages/s3-request-presigner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ export class S3RequestPresigner implements RequestPresigner {
public async presignRequest(
requestToSign: IHttpRequest,
expiration: DateInput,
options?: RequestSigningArguments
{ unsignableHeaders = new Set(), ...options }: RequestSigningArguments = {}
): Promise<IHttpRequest> {
unsignableHeaders.add("content-type");
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
return this.signer.presignRequest(requestToSign, expiration, options);
return this.signer.presignRequest(requestToSign, expiration, {
unsignableHeaders,
...options
});
}
}

0 comments on commit d26a90b

Please sign in to comment.