Skip to content

Commit cf0cd38

Browse files
committed
Fix #358 - migrate to S3 policy v4 to support AWS4-HMAC-SHA256
1 parent b7ab455 commit cf0cd38

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

client/modules/IDE/actions/uploader.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ export function dropzoneSendingCallback(file, xhr, formData) {
7777
Object.keys(file.postData).forEach((key) => {
7878
formData.append(key, file.postData[key]);
7979
});
80-
formData.append('Content-type', file.type);
81-
formData.append('Content-length', '');
82-
formData.append('acl', 'public-read');
8380
}
8481
};
8582
}

package-lock.json

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
"request": "^2.88.2",
216216
"request-promise": "^4.2.5",
217217
"reselect": "^4.0.0",
218-
"s3-policy": "^0.2.0",
218+
"s3-policy-v4": "0.0.3",
219219
"sass-extract": "^2.1.0",
220220
"sass-extract-js": "^0.4.0",
221221
"sass-extract-loader": "^1.1.0",

server/controllers/aws.controller.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid from 'node-uuid';
2-
import policy from 's3-policy';
2+
import S3Policy from 's3-policy-v4';
33
import s3 from '@auth0/s3';
44
import { getProjectsForUserId } from './project.controller';
55
import { findUserByUsername } from './user.controller';
@@ -80,22 +80,19 @@ export function signS3(req, res) {
8080
}
8181
const fileExtension = getExtension(req.body.name);
8282
const filename = uuid.v4() + fileExtension;
83-
const acl = 'public-read';
84-
const p = policy({
83+
const acl = 'private';
84+
const policy = S3Policy.generate({
8585
acl,
86-
secret: process.env.AWS_SECRET_KEY,
87-
length: 5000000, // in bytes?
88-
bucket: process.env.S3_BUCKET,
8986
key: filename,
90-
expires: new Date(Date.now() + 60000),
87+
bucket: process.env.S3_BUCKET,
88+
contentType: req.body.type,
89+
region: process.env.AWS_REGION,
90+
accessKey: process.env.AWS_ACCESS_KEY,
91+
secretKey: process.env.AWS_SECRET_KEY,
92+
// metadata: {'x-amz-meta-lat': '41.891',...} (optional)
93+
metadata: []
9194
});
92-
const result = {
93-
AWSAccessKeyId: process.env.AWS_ACCESS_KEY,
94-
key: `${req.body.userId}/${filename}`,
95-
policy: p.policy,
96-
signature: p.signature
97-
};
98-
res.json(result);
95+
res.json(policy);
9996
}
10097

10198
export function copyObjectInS3(url, userId) {

0 commit comments

Comments
 (0)