Skip to content

Conversation

@BoogeyMan24
Copy link

Summary

The documentation was stating that:

// Generate presigned URL for writing (PUT)
// Specify ContentType to restrict uploads to a specific file type
const putUrl = await getSignedUrl(
	S3,
	new PutObjectCommand({
		Bucket: "my-bucket",
		Key: "image.png",
		ContentType: "image/png",
	}),
	{ expiresIn: 3600 },
);

However, ContentType header is NOT signed by default and signableHeaders must be added for the header to be signed:

// Generate presigned URL for writing (PUT)
// Specify ContentType and add it to signableHeaders to restrict uploads to a specific file type
const putUrl = await getSignedUrl(
	S3,
	new PutObjectCommand({
		Bucket: "my-bucket",
		Key: "image.png",
		ContentType: "image/png",
	}),
	{ 
		expiresIn: 3600,
		signableHeaders: new Set(["content-type"]),
	},
);

This PR adds the required signableHeaders to the examples in the documentation so that Content-Type is signed.
Source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-s3-request-presigner/

Screenshots (optional)

none

Documentation checklist

not sure how to make a changelog. If its necessary, how do I do it?

Content-Type is not signed by default. It must be added to signableHeaders for it to be signed. Added a warning and a link to official docs to ensure people protect their urls correctly.
…/s3/presigned-ruls

Updated the presigned URL generation example to include signableHeaders for ContentType restriction.
Before: "Specify ContentTypea and add it to the signableHeaders..."
Now: "Specify ContentType and add it to signableHeaders"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants