@contember/engine-s3-plugin 2.0.9 → 2.0.11
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/dist/development/src/S3Service.cjs +3 -2
- package/dist/development/src/S3Service.cjs.map +1 -1
- package/dist/development/src/S3Service.js +3 -2
- package/dist/development/src/S3Service.js.map +1 -1
- package/dist/production/src/S3Service.cjs +3 -2
- package/dist/production/src/S3Service.cjs.map +1 -1
- package/dist/production/src/S3Service.js +3 -2
- package/dist/production/src/S3Service.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/S3Service.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/S3Service.ts +4 -2
- package/tests/cases/signRequest.test.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-s3-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
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.
|
|
27
|
-
"@contember/graphql-utils": "2.0.
|
|
28
|
-
"@contember/typesafe": "2.0.
|
|
26
|
+
"@contember/engine-plugins": "2.0.11",
|
|
27
|
+
"@contember/graphql-utils": "2.0.11",
|
|
28
|
+
"@contember/typesafe": "2.0.11",
|
|
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
|
-
|
|
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 =
|
|
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 })
|