Skip to content

Commit 8153de7

Browse files
committed
fix
1 parent 0538835 commit 8153de7

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

spec/ParseFile.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,38 @@ describe('Parse.File testing', () => {
14611461
}
14621462
});
14631463

1464+
it('default should block SVG files', async () => {
1465+
await reconfigureServer({
1466+
fileUpload: {
1467+
enableForPublic: true,
1468+
},
1469+
});
1470+
const headers = {
1471+
'X-Parse-Application-Id': 'test',
1472+
'X-Parse-REST-API-Key': 'rest',
1473+
};
1474+
const svgContent = Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>').toString('base64');
1475+
for (const extension of ['svg', 'SVG', 'Svg']) {
1476+
await expectAsync(
1477+
request({
1478+
method: 'POST',
1479+
headers: headers,
1480+
url: `http://localhost:8378/1/files/malicious.${extension}`,
1481+
body: JSON.stringify({
1482+
_ApplicationId: 'test',
1483+
_JavaScriptKey: 'test',
1484+
_ContentType: 'image/svg+xml',
1485+
base64: svgContent,
1486+
}),
1487+
}).catch(e => {
1488+
throw new Error(e.data.error);
1489+
})
1490+
).toBeRejectedWith(
1491+
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, `File upload of extension ${extension} is disabled.`)
1492+
);
1493+
}
1494+
});
1495+
14641496
it('works with a period in the file name', async () => {
14651497
await reconfigureServer({
14661498
fileUpload: {

src/Options/Definitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,9 @@ module.exports.FileUploadOptions = {
10591059
},
10601060
fileExtensions: {
10611061
env: 'PARSE_SERVER_FILE_UPLOAD_FILE_EXTENSIONS',
1062-
help: "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 `^(?![xXsS]?[hH][tT][mM][lL]?$)` which allows any file extension except those MIME types that are mapped to `text/html` and are rendered as website by a web browser.",
1062+
help: "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 and SVG files are especially problematic as they may be used by an attacker who uploads a HTML form or SVG image 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 `^(?!([xXsS]?[hH][tT][mM][lL]?|[sS][vV][gG])$)` which allows any file extension except those that are rendered as website or active content by a web browser.",
10631063
action: parsers.arrayParser,
1064-
default: ['^(?![xXsS]?[hH][tT][mM][lL]?$)'],
1064+
default: ['^(?!([xXsS]?[hH][tT][mM][lL]?|[sS][vV][gG])$)'],
10651065
},
10661066
};
10671067
/* The available log levels for Parse Server logging. Valid values are:<br>- `'error'` - Error level (highest priority)<br>- `'warn'` - Warning level<br>- `'info'` - Info level (default)<br>- `'verbose'` - Verbose level<br>- `'debug'` - Debug level<br>- `'silly'` - Silly level (lowest priority) */

src/Options/docs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ export interface PasswordPolicyOptions {
648648
}
649649

650650
export interface FileUploadOptions {
651-
/* 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 `^(?![xXsS]?[hH][tT][mM][lL]?$)` which allows any file extension except those MIME types that are mapped to `text/html` and are rendered as website by a web browser.
652-
:DEFAULT: ["^(?![xXsS]?[hH][tT][mM][lL]?$)"] */
651+
/* 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 and SVG files are especially problematic as they may be used by an attacker who uploads a HTML form or SVG image 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 `^(?!([xXsS]?[hH][tT][mM][lL]?|[sS][vV][gG])$)` which allows any file extension except those that are rendered as website or active content by a web browser.
652+
:DEFAULT: ["^(?!([xXsS]?[hH][tT][mM][lL]?|[sS][vV][gG])$)"] */
653653
fileExtensions: ?(string[]);
654654
/* Is true if file upload should be allowed for anonymous users.
655655
:DEFAULT: false */

0 commit comments

Comments
 (0)