Skip to content

Commit 7f3ad07

Browse files
authored
Merge pull request #126 from nspcc-dev/feature/125_ensure_content_type_correctness
2 parents acb5b36 + 7b7801f commit 7f3ad07

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Home.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ const Home = ({
3232
const fileUploadMbLimit: number = 200 * 1024 * 1024;
3333

3434
const handleAllFiles = (files: any) => {
35+
const unsupportedFiles: any[] = [];
3536
for (let i = 0; i < files.length; i += 1) {
36-
handleFile(files[i], i === (files.length - 1));
37+
if (['application/javascript', 'text/javascript', 'application/xhtml+xml', 'text/html', 'text/htmlh'].indexOf(files[i].type) === -1) {
38+
handleFile(files[i], i === (files.length - 1));
39+
} else {
40+
unsupportedFiles.push(files[i].name);
41+
}
42+
}
43+
44+
if (unsupportedFiles.length > 0) {
45+
onModal('failed', `Selected file${unsupportedFiles.length > 1 ? 's' : ''} (${unsupportedFiles.join(', ')}) can't be uploaded because of type restrictions (HTML and JS are forbidden)`);
3746
}
3847
};
3948

@@ -110,7 +119,7 @@ const Home = ({
110119
'Email': user.XAttributeEmail,
111120
}),
112121
'X-Neofs-Expiration-Duration': lifetimeData,
113-
'Content-Type': file.type,
122+
'Content-Type': file.type === '' ? 'application/octet-stream' : '',
114123
}).then((res: any) => {
115124
res['filename'] = file.name;
116125
setUploadedObjects((uploadedObjectsTemp: UploadedObject[]) => [...uploadedObjectsTemp, res]);

0 commit comments

Comments
 (0)