Skip to content

Commit af1fe53

Browse files
committed
wip
1 parent e3d9b68 commit af1fe53

File tree

7 files changed

+26
-35
lines changed

7 files changed

+26
-35
lines changed

package-lock.json

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

spec/ParseFile.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Parse.File testing', () => {
4141
await reconfigureServer({
4242
fileUpload: {
4343
enableForPublic: true,
44-
fileExtensions: '*',
44+
fileExtensions: ['*'],
4545
},
4646
});
4747
let response = await request({
@@ -358,7 +358,7 @@ describe('Parse.File testing', () => {
358358
await reconfigureServer({
359359
fileUpload: {
360360
enableForPublic: true,
361-
fileExtensions: '*',
361+
fileExtensions: ['*'],
362362
},
363363
});
364364
const headers = {
@@ -1310,7 +1310,7 @@ describe('Parse.File testing', () => {
13101310
fileExtensions: 1,
13111311
},
13121312
})
1313-
).toBeRejectedWith('fileUpload.fileExtensions must be an array or string.');
1313+
).toBeRejectedWith('fileUpload.fileExtensions must be an array.');
13141314
});
13151315
});
13161316
describe('fileExtensions', () => {

src/Config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,8 @@ export class Config {
438438
}
439439
if (fileUpload.fileExtensions === undefined) {
440440
fileUpload.fileExtensions = FileUploadOptions.fileExtensions.default;
441-
} else if (
442-
!Array.isArray(fileUpload.fileExtensions) &&
443-
typeof fileUpload.fileExtensions !== 'string'
444-
) {
445-
throw 'fileUpload.fileExtensions must be an array or string.';
441+
} else if (!Array.isArray(fileUpload.fileExtensions)) {
442+
throw 'fileUpload.fileExtensions must be an array.';
446443
}
447444
}
448445

src/Options/Definitions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This code has been generated by resources/buildConfigDefinitions.js
44
Do not edit manually, but update Options/index.js
55
*/
66
var parsers = require('./parsers');
7+
78
module.exports.SchemaOptions = {
89
afterMigration: {
910
env: 'PARSE_SERVER_SCHEMA_AFTER_MIGRATION',
@@ -886,7 +887,8 @@ module.exports.FileUploadOptions = {
886887
env: 'PARSE_SERVER_FILE_UPLOAD_FILE_EXTENSIONS',
887888
help:
888889
"Sets the allowed file extensions for uploading files. The extension is defined as an array of file extensions, or a regex pattern.<br><br>It is recommended to restrict the file upload extensions as much as possible. HTML files are especially problematic as they may be used by an attacker who uploads a HTML form to look legitimate under your app's domain name, or to compromise the session token of another user via accessing the browser's local storage.<br><br>Defaults to `^[^hH][^tT][^mM][^lL]?$` which allows any file extension except HTML files.",
889-
default: '^[^hH][^tT][^mM][^lL]?$',
890+
action: parsers.arrayParser,
891+
default: ['^[^hH][^tT][^mM][^lL]?$'],
890892
},
891893
};
892894
module.exports.DatabaseOptions = {

src/Options/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
* @property {Boolean} enableForAnonymousUser Is true if file upload should be allowed for anonymous users.
205205
* @property {Boolean} enableForAuthenticatedUser Is true if file upload should be allowed for authenticated users.
206206
* @property {Boolean} enableForPublic Is true if file upload should be allowed for anyone, regardless of user authentication.
207-
* @property {String} fileExtensions Sets the allowed file extensions for uploading files. The extension is defined as an array of file extensions, or a regex pattern.<br><br>It is recommended to restrict the file upload extensions as much as possible. HTML files are especially problematic as they may be used by an attacker who uploads a HTML form to look legitimate under your app's domain name, or to compromise the session token of another user via accessing the browser's local storage.<br><br>Defaults to `^[^hH][^tT][^mM][^lL]?$` which allows any file extension except HTML files.
207+
* @property {String[]} fileExtensions Sets the allowed file extensions for uploading files. The extension is defined as an array of file extensions, or a regex pattern.<br><br>It is recommended to restrict the file upload extensions as much as possible. HTML files are especially problematic as they may be used by an attacker who uploads a HTML form to look legitimate under your app's domain name, or to compromise the session token of another user via accessing the browser's local storage.<br><br>Defaults to `^[^hH][^tT][^mM][^lL]?$` which allows any file extension except HTML files.
208208
*/
209209

210210
/**

src/Options/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ export interface PasswordPolicyOptions {
498498

499499
export interface FileUploadOptions {
500500
/* Sets the allowed file extensions for uploading files. The extension is defined as an array of file extensions, or a regex pattern.<br><br>It is recommended to restrict the file upload extensions as much as possible. HTML files are especially problematic as they may be used by an attacker who uploads a HTML form to look legitimate under your app's domain name, or to compromise the session token of another user via accessing the browser's local storage.<br><br>Defaults to `^[^hH][^tT][^mM][^lL]?$` which allows any file extension except HTML files.
501-
:DEFAULT: ^[^hH][^tT][^mM][^lL]?$ */
502-
fileExtensions: ?string;
501+
:DEFAULT: ["^[^hH][^tT][^mM][^lL]?$"] */
502+
fileExtensions: ?(string[]);
503503
/* Is true if file upload should be allowed for anonymous users.
504504
:DEFAULT: false */
505505
enableForAnonymousUser: ?boolean;

src/Routers/FilesRouter.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,15 @@ export class FilesRouter {
141141
const fileExtensions = config.fileUpload?.fileExtensions;
142142
if (!isMaster && fileExtensions) {
143143
const isValidExtension = extension => {
144-
if (fileExtensions === '*') {
145-
return true;
146-
}
147-
if (Array.isArray(fileExtensions)) {
148-
if (fileExtensions.includes(extension)) {
144+
return fileExtensions.some(ext => {
145+
if (ext === '*') {
149146
return true;
150147
}
151-
} else {
152148
const regex = new RegExp(fileExtensions);
153149
if (regex.test(extension)) {
154150
return true;
155151
}
156-
}
152+
});
157153
};
158154
let extension = filename.includes('.') ? filename.split('.')[1] : contentType.split('/')[1];
159155
extension = extension.split(' ').join('');

0 commit comments

Comments
 (0)