@contember/engine-s3-plugin 2.0.8 → 2.0.10

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.0.8",
3
+ "version": "2.0.10",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -23,9 +23,9 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@contember/engine-plugins": "2.0.8",
27
- "@contember/graphql-utils": "2.0.8",
28
- "@contember/typesafe": "2.0.8",
26
+ "@contember/engine-plugins": "2.0.10",
27
+ "@contember/graphql-utils": "2.0.10",
28
+ "@contember/typesafe": "2.0.10",
29
29
  "mime-types": "^2.1.35",
30
30
  "picomatch": "^4.0.2",
31
31
  "qs": "^6.13.0",
package/src/S3Service.ts CHANGED
@@ -103,12 +103,14 @@ export class S3Service {
103
103
  if (objectKey.startsWith(publicPrefix)) {
104
104
  objectKey = objectKey.substring(publicPrefix.length)
105
105
  }
106
- if (this.config.prefix && !objectKey.startsWith(this.config.prefix)) {
106
+ // the separator is a part of the prefix: without it, a project prefixed "blog" reaches into "blog-staging" in a shared bucket
107
+ const prefix = this.config.prefix ? this.config.prefix + '/' : ''
108
+ if (prefix && !objectKey.startsWith(prefix)) {
107
109
  throw new ForbiddenError(
108
110
  `Given object key "${objectKey}" does not start with a project prefix "${this.config.prefix}"`,
109
111
  )
110
112
  }
111
- const localObjectKey = this.config.prefix ? objectKey.substring(this.config.prefix.length + 1) : objectKey
113
+ const localObjectKey = objectKey.substring(prefix.length)
112
114
  this.authorizator.verifyReadAccess({ key: localObjectKey })
113
115
 
114
116
  const url = this.signer.sign({
@@ -33,6 +33,13 @@ test('sign s3 request - prefix', () => {
33
33
  expect(signed.url).toEqual('https://test.s3.eu-central-1.amazonaws.com/lorem/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=f6c69dc306422c2b3242c9d9d42147336817720ffae249af8bd91cc7062e9f6d&X-Amz-SignedHeaders=host')
34
34
  })
35
35
 
36
+ test('sign s3 request - a sibling prefix is not a prefix', () => {
37
+ const service = createS3Service('test', 'lorem')
38
+ expect(() => service.getSignedReadUrl({ objectKey: 'loremipsum/foo.jpg', expiration: null })).toThrow(
39
+ 'Given object key "loremipsum/foo.jpg" does not start with a project prefix "lorem"',
40
+ )
41
+ })
42
+
36
43
  test('sign upload', () => {
37
44
  const service = createS3Service('test')
38
45
  const signed = service.getSignedUploadUrl({ contentType: 'image/jpeg', acl: 'PUBLIC_READ', expiration: 1800, contentDisposition: null, extension: null, fileName: null, prefix: null, suffix: null, size: null })