Skip to content

Commit

Permalink
Address existing issues involving paths in S3 and Signature usages (#104
Browse files Browse the repository at this point in the history
)

* Activate signature's URIencoding as a default for S3Client

* Ensure the Endpoint type is also exposed by the aws.js bundle

* Add leading slash to request path when signing and presiging

* Update build files

* Apply pull request review suggestions

* Update build files
  • Loading branch information
oleiade authored May 14, 2024
1 parent bdc2d53 commit 5073f0a
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dist/aws.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aws.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { InvalidSignatureError } from './internal/signature'
export { AWSConfig, InvalidAWSConfigError } from './internal/config'
export { AMZ_CONTENT_SHA256_HEADER, UNSIGNED_PAYLOAD } from './internal/constants'
export { KMSClient, KMSDataKey, KMSServiceError } from './internal/kms'
export { Endpoint } from './internal/endpoint'
export { SignatureV4 } from './internal/signature'
export { S3Bucket, S3Client, S3Object, S3ServiceError } from './internal/s3'
export {
Expand Down
7 changes: 6 additions & 1 deletion src/internal/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export class S3Client extends AWSClient {
secretAccessKey: this.awsConfig.secretAccessKey,
sessionToken: this.awsConfig.sessionToken,
},
uriEscapePath: false,

// S3 requires the URI path to be escaped
uriEscapePath: true,

// Signing S3 requests requires the payload to be hashed
// and the checksum to be included in the request headers.
applyChecksum: true,
})
}
Expand Down
10 changes: 10 additions & 0 deletions src/internal/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export class SignatureV4 {
// If a request path was provided, add it to the URL
let url = request.endpoint.href
if (request.path) {
// Ensure there is a trailing slash at the end of the URL
// so that appending the path does not result in a malformed URL.
url = url.endsWith('/') ? url : url + '/'

// Append the path to the URL
url += request.path
}

Expand Down Expand Up @@ -266,6 +271,11 @@ export class SignatureV4 {
// If a request path was provided, add it to the URL
let url = request.endpoint.href
if (request.path) {
// Ensure there is a trailing slash at the end of the URL
// so that appending the path does not result in a malformed URL.
url = url.endsWith('/') ? url : url + '/'

// Append the path to the URL
url += request.path
}

Expand Down

0 comments on commit 5073f0a

Please sign in to comment.