From eb572878163035359e8480d439e7aeb224e51802 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 4 Dec 2020 06:15:52 -0800 Subject: [PATCH] Add restrictions to allowed extensions for File System Access API These restrictions apply to showOpenFilePicker and showSaveFilePicker. Existing restriction: - Extension must start with "." New restrictions: - Allowed code points: [A-Za-z0-9+.] - Extension length cannot exceed to 16, inclusive of leading "." - Extension cannot end with "." - Extension cannot end with "local" or "lnk" Bug: 1137247, 1140410, 1140417, 1152327 Change-Id: I593f7ca60e05177402885bd3026add16b3a07d0c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568534 Reviewed-by: Marijn Kruisselbrink Commit-Queue: Austin Sullivan Cr-Commit-Position: refs/heads/master@{#833695} --- .../showPicker-errors.https.window.js | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/native-file-system/showPicker-errors.https.window.js b/native-file-system/showPicker-errors.https.window.js index e8f0d3f5404851..d1dabf37da8305 100644 --- a/native-file-system/showPicker-errors.https.window.js +++ b/native-file-system/showPicker-errors.https.window.js @@ -80,9 +80,39 @@ function define_file_picker_error_tests(showPickerMethod) { showPickerMethod + ': MIME type can\'t have invalid characters in subtype.'); - promise_test(async t => { - await promise_rejects_js(t, TypeError, self[showPickerMethod]({ - types: [{accept: {'text/plain': ['.txt', 'txt']}}] - })); - }, showPickerMethod + ': extension has to start with ".".'); + const invalid_extensions = { + '.extensiontoolong': 'extension length more than 16.', + '.txt.': 'extenstion ends with "."', + 'txt': 'extenstion does not start with "."', + '.$txt' : 'illegal character "$"', + '.t { + await promise_rejects_js( + t, TypeError, + self[showPickerMethod]( + { types: [{ accept: { 'text/plain': ['.txt', extension] } }] })); + }, showPickerMethod + ': invalid extension "' + extension + '". ' + description + "."); +} \ No newline at end of file