From 3869b4104196ca049cc8d63cbaad836a4a0935e3 Mon Sep 17 00:00:00 2001 From: Roberto Dip Date: Thu, 26 Oct 2023 18:20:24 -0300 Subject: [PATCH] prevent a bug preventing .mobileconfig uploads in Linux/Windows (#14716) For #14056, per the [mdn web docs](https://developer.mozilla.org/en-US/docs/Web/API/File/type) > Note: Based on the current implementation, browsers won't actually > read the bytestream of a file to determine its media type. It is assumed > based on the file extension; a PNG image file renamed to .txt would give > "text/plain" and not "image/png". Moreover, file.type is generally > reliable only for common file types like images, HTML documents, audio > and video. Uncommon file extensions would return an empty string. Client > configuration (for instance, the Windows Registry) may result in > unexpected values even for common types. Developers are advised not to > rely on this property as a sole validation scheme. --- changes/14056-file-ext | 1 + .../OSSettings/cards/CustomSettings/CustomSettings.tsx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changes/14056-file-ext diff --git a/changes/14056-file-ext b/changes/14056-file-ext new file mode 100644 index 0000000000..ff78c65bcc --- /dev/null +++ b/changes/14056-file-ext @@ -0,0 +1 @@ +* Fixed a bug preventing Windows and Linux users to upload .mobileconfig files in the UI. diff --git a/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/CustomSettings.tsx b/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/CustomSettings.tsx index bf27f50674..eb69a5ad1e 100644 --- a/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/CustomSettings.tsx +++ b/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/CustomSettings.tsx @@ -61,7 +61,9 @@ const CustomSettings = ({ const file = files[0]; if ( - file.type !== "application/x-apple-aspen-config" || + // file.type might be empty on some systems as uncommon file extensions + // would return an empty string. + (file.type !== "" && file.type !== "application/x-apple-aspen-config") || !file.name.includes(".mobileconfig") ) { renderFlash("error", UPLOAD_ERROR_MESSAGES.wrongType.message);