Skip to content

Commit fe02d3e

Browse files
authored
refactor: Server crash when uploading file without extension; fixes security vulnerability [GHSA-792q-q67h-w579](GHSA-792q-q67h-w579) (#8779)
1 parent 5dd3aa0 commit fe02d3e

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
@@ -1432,6 +1432,34 @@ describe('Parse.File testing', () => {
14321432
}
14331433
});
14341434

1435+
it('allows file without extension', async () => {
1436+
await reconfigureServer({
1437+
fileUpload: {
1438+
enableForPublic: true,
1439+
fileExtensions: ['^[^hH][^tT][^mM][^lL]?$'],
1440+
},
1441+
});
1442+
const headers = {
1443+
'X-Parse-Application-Id': 'test',
1444+
'X-Parse-REST-API-Key': 'rest',
1445+
};
1446+
1447+
const values = ['filenamewithoutextension'];
1448+
1449+
for (const value of values) {
1450+
await expectAsync(
1451+
request({
1452+
method: 'POST',
1453+
headers: headers,
1454+
url: `http://localhost:8378/1/files/${value}`,
1455+
body: '<html></html>\n',
1456+
}).catch(e => {
1457+
throw new Error(e.data.error);
1458+
})
1459+
).toBeResolved();
1460+
}
1461+
});
1462+
14351463
it('works with array', async () => {
14361464
await reconfigureServer({
14371465
fileUpload: {

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)