@contember/engine-s3-plugin 2.2.0-alpha.18 → 2.2.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-s3-plugin",
3
- "version": "2.2.0-alpha.18",
3
+ "version": "2.2.0-alpha.19",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -23,17 +23,14 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@contember/engine-plugins": "2.2.0-alpha.18",
27
- "@contember/graphql-utils": "2.2.0-alpha.18",
28
- "@contember/typesafe": "2.2.0-alpha.18",
26
+ "@contember/engine-plugins": "2.2.0-alpha.19",
27
+ "@contember/graphql-utils": "2.2.0-alpha.19",
28
+ "@contember/typesafe": "2.2.0-alpha.19",
29
29
  "mime-types": "^3.0.2",
30
- "picomatch": "^4.0.3",
31
- "qs": "^6.15.0",
32
- "uuid": "^13.0.0"
30
+ "picomatch": "^4.0.3"
33
31
  },
34
32
  "devDependencies": {
35
33
  "@types/mime-types": "^3.0.1",
36
- "@types/qs": "^6.15.0",
37
34
  "graphql": "^16.13.1"
38
35
  },
39
36
  "peerDependencies": {
package/src/S3Signer.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { resolveS3Endpoint, S3Config } from './Config.js'
2
2
  import { Providers } from '@contember/engine-plugins'
3
- import qs from 'qs'
4
3
  import { BinaryLike, createHash, createHmac } from 'node:crypto'
5
4
 
6
5
  interface S3Request {
@@ -18,6 +17,10 @@ const methods: Record<S3Request['action'], string> = {
18
17
 
19
18
  const hmac = (secret: BinaryLike, data: BinaryLike) => createHmac('sha256', secret).update(data).digest()
20
19
 
20
+ // SigV4 canonical query encoding (RFC 3986): only A-Z a-z 0-9 - . _ ~ stay unescaped.
21
+ const encodeRfc3986 = (value: string): string =>
22
+ encodeURIComponent(value).replace(/[!'()*]/g, char => '%' + char.charCodeAt(0).toString(16).toUpperCase())
23
+
21
24
  const hash = (data: BinaryLike) => createHash('sha256').update(data).digest('hex')
22
25
 
23
26
  const unsignableHeaders = ['authorization', 'user-agent', 'content-type', 'expect', 'x-amzn-trace-id']
@@ -77,7 +80,7 @@ export class S3Signer {
77
80
  }
78
81
  }
79
82
  const qsSorted = sortMap(queryString)
80
- return qs.stringify(qsSorted)
83
+ return Object.entries(qsSorted).map(([key, value]) => `${encodeRfc3986(key)}=${encodeRfc3986(value)}`).join('&')
81
84
  }
82
85
 
83
86
  private getScope(dateFormatted: string) {
@@ -158,3 +158,21 @@ test('bucket with dot', () => {
158
158
  'https://s3.eu-central-1.amazonaws.com/test.foo/foo.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=test%2F20210702%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20210702T172200Z&X-Amz-Expires=3600&X-Amz-Signature=811a809196e60413e0e54e51d3dd91ab73ad1482b61e5371864d25d43ba642ff&X-Amz-SignedHeaders=host',
159
159
  )
160
160
  })
161
+
162
+ test('sign upload - query values are RFC 3986 encoded', () => {
163
+ const service = createS3Service('test')
164
+ const signed = service.getSignedUploadUrl({
165
+ contentType: `application/x-test; name="a b!'()*~-_.ž/+=&?#%"`,
166
+ acl: 'PRIVATE',
167
+ expiration: null,
168
+ contentDisposition: null,
169
+ extension: 'bin',
170
+ fileName: null,
171
+ prefix: null,
172
+ suffix: null,
173
+ size: null,
174
+ })
175
+ expect(signed.url).toEqual(
176
+ 'https://test.s3.eu-central-1.amazonaws.com/9fce3907-ff2b-45bb-b4ce-eff5527dd315.bin?Cache-Control=immutable&Content-Type=application%2Fx-test%3B%20name%3D%22a%20b%21%27%28%29%2A~-_.%C5%BE%2F%2B%3D%26%3F%23%25%22&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=test%2F20210702%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20210702T172200Z&X-Amz-Expires=3600&X-Amz-Signature=9e1cfdb2217c8707980d6ecc264b752c2526696845ab257c7dab555c31268ebc&X-Amz-SignedHeaders=cache-control%3Bhost%3Bx-amz-acl&x-amz-acl=private',
177
+ )
178
+ })