Skip to content

[WC-3051]: Improve file extension validation in file uploader web widget #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"mime-types": "patches/mime-types.patch",
"rc-trigger": "patches/rc-trigger.patch"
"rc-trigger": "patches/rc-trigger.patch",
"react-dropzone": "patches/react-dropzone.patch"
},
"onlyBuiltDependencies": [
"canvas"
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/file-uploader/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mendix/file-uploader",
"moduleName": "File Uploader module",
"version": "2.2.2",
"version": "2.3.0",
"copyright": "© Mendix Technology BV 2025. All rights reserved.",
"license": "Apache-2.0",
"private": true,
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/file-uploader-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- We improved the file extension validation to allow special characters like dashes and plus signs (e.g., '.tar-gz', '.c++').

- We clarified error messages for invalid file extensions to better explain the expected format.

- We fixed an issue where file uploader can still add more files when refreshed eventhough the number of maximum uploaded files has been reached.

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ describe("parseAllowedFormats", () => {
"Value 'application-pdf' is not recognized. Accepted format: 'image/jpeg'"
);
});
test("handles extensions with special characters like dashes and plus signs", () => {
const input: AllowedFileFormatsType[] = [
{
configMode: "advanced",
typeFormatDescription: dynamicValue("special-extensions"),
predefinedType: "pdfFile",
mimeType: "application/x-custom",
extensions: ".tar-gz,.js-map,.c++"
}
];

expect(parseAllowedFormats(input)).toEqual([
{
description: "special-extensions",
entries: [["application/x-custom", [".tar-gz", ".js-map", ".c++"]]]
}
]);
});
test("throws on extension without leading dot", () => {
const input: AllowedFileFormatsType[] = [
{
configMode: "advanced",
typeFormatDescription: dynamicValue("test"),
predefinedType: "pdfFile",
mimeType: "text/*",
extensions: ".txt,pdf"
}
];

expect(() => parseAllowedFormats(input)).toThrow(
"Value 'pdf' is not recognized. Extension must start with a dot and contain only valid filename characters"
);
});

test("throws on incorrect extension format", () => {
const input: AllowedFileFormatsType[] = [
{
Expand All @@ -106,6 +140,24 @@ describe("parseAllowedFormats", () => {
}
];

expect(() => parseAllowedFormats(input)).toThrow("Value 'abc' is not recognized. Accepted format: '.pdf'");
expect(() => parseAllowedFormats(input)).toThrow(
"Value 'abc' is not recognized. Extension must start with a dot and contain only valid filename characters"
);
});

test("throws on extension with dot in the middle", () => {
const input: AllowedFileFormatsType[] = [
{
configMode: "advanced",
typeFormatDescription: dynamicValue("test"),
predefinedType: "pdfFile",
mimeType: "text/*",
extensions: ".txt,.config.json"
}
];

expect(() => parseAllowedFormats(input)).toThrow(
"Value '.config.json' is not recognized. Extension must start with a dot and contain only valid filename characters"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ function parseExtensionsList(config: string): string[] {
.map(c => c.trim())
.filter(c => c)
.map(c => {
if (/^\.\w+$/.test(c)) {
// ".ext" string
if (/^\.[^/\\?*<>|:".]+$/.test(c)) {
// ".ext" string - allowing most characters except those invalid in filenames
return c;
}

throw new Error(`Value '${c}' is not recognized. Accepted format: '.pdf'`);
throw new Error(
`Value '${c}' is not recognized. Extension must start with a dot and contain only valid filename characters (e.g. '.pdf', '.doc', '.tar-gz')`
);
});
}
34 changes: 34 additions & 0 deletions patches/react-dropzone.patch

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading