jmuehlner commented on code in PR #838:
URL: https://github.com/apache/guacamole-client/pull/838#discussion_r1167629502


##########
guacamole/src/main/frontend/src/app/import/controllers/importConnectionsController.js:
##########
@@ -640,8 +655,23 @@ 
angular.module('import').controller('importConnectionsController', ['$scope', '$
 
             else {
 
+                const fileData = e.target.result;
+
+                // Check if the file has a header of a known-bad type
+                if (_.some(ZIP_SIGNATURES,
+                        signature => fileData.startsWith(signature))) {
+
+                    // Throw an error and abort processing
+                    handleError(new ParseError({
+                        message: "Invalid file type detected",
+                        key: 'IMPORT.ERROR_DETECTED_INVALID_TYPE'
+                    }));
+                    return;

Review Comment:
   If somebody just directly uploads a `.mp4` or `.tar` file, the MIME type 
check will reject it before it ever gets here, and they'll get an error 
specifically telling them that they've provided an invalid file type, e.g. 
`Unsupported file type: "video/mp4"`.
   
   This is specifically to handle the case that somebody uploads a CSV, YAML, 
or JSON file that's actually an excel document, which is probably much more 
likely than them uploading a `.csv` file that's actually a video.
   
   If binary garbage _is_ provided to the parsers, this is what seems to 
generally happen for each case:
   
   - CSV parser throws a an error with message `Argument must be a Buffer` (so 
ugly we specifically catch and handle it)
   - JSON parser throws an error with a message like `Unexpected token 'ë', 
"ëѧ%øtÅ9¡<"... is not valid JSON`
   - The YAML parser seems to actually parse the binary garbage, generally 
producing an object that's caught by one of our checks further on, producing 
this error `The provided file must contain a list of connections`
   
   Obviously there's no way we can guarantee that a file won't have binary 
garbage in it without preprocessing the entire file, which has a huge 
performance cost. 
   
   This check is intended to catch the likely most common case and throw a 
friendlier error before an attempt is made to parse the file at all, since the 
errors generated by the parsers themselves are less friendly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to