Skip to content

Commit fd86278

Browse files
authored
fix: Server crash when uploading file without extension; fixes security vulnerability [GHSA-792q-q67h-w579](GHSA-792q-q67h-w579) (#8781)
1 parent 3602ecb commit fd86278

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Diff for: spec/ParseFile.spec.js

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

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

Diff for: src/Routers/FilesRouter.js

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

164-
if (!isValidExtension(extension)) {
164+
if (extension && !isValidExtension(extension)) {
165165
next(
166166
new Parse.Error(
167167
Parse.Error.FILE_SAVE_ERROR,

0 commit comments

Comments
 (0)