Skip to content

Commit 686a9f2

Browse files
authored
fix: Server crash when uploading file without extension; fixes security vulnerability [GHSA-792q-q67h-w579](GHSA-792q-q67h-w579) (#8782)
1 parent 0bb63d8 commit 686a9f2

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

spec/ParseFile.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,34 @@ describe('Parse.File testing', () => {
13661366
);
13671367
});
13681368

1369+
it('allows file without extension', async () => {
1370+
await reconfigureServer({
1371+
fileUpload: {
1372+
enableForPublic: true,
1373+
fileExtensions: ['^[^hH][^tT][^mM][^lL]?$'],
1374+
},
1375+
});
1376+
const headers = {
1377+
'X-Parse-Application-Id': 'test',
1378+
'X-Parse-REST-API-Key': 'rest',
1379+
};
1380+
1381+
const values = ['filenamewithoutextension'];
1382+
1383+
for (const value of values) {
1384+
await expectAsync(
1385+
request({
1386+
method: 'POST',
1387+
headers: headers,
1388+
url: `http://localhost:8378/1/files/${value}`,
1389+
body: '<html></html>\n',
1390+
}).catch(e => {
1391+
throw new Error(e.data.error);
1392+
})
1393+
).toBeResolved();
1394+
}
1395+
});
1396+
13691397
it('works with array', async () => {
13701398
await reconfigureServer({
13711399
fileUpload: {

src/Routers/FilesRouter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ export class FilesRouter {
157157
} else if (contentType && contentType.includes('/')) {
158158
extension = contentType.split('/')[1];
159159
}
160-
extension = extension.split(' ').join('');
160+
extension = extension?.split(' ')?.join('');
161161

162-
if (!isValidExtension(extension)) {
162+
if (extension && !isValidExtension(extension)) {
163163
next(
164164
new Parse.Error(
165165
Parse.Error.FILE_SAVE_ERROR,

0 commit comments

Comments
 (0)