mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-926: Better handling for invalid import files.
This commit is contained in:
@@ -50,6 +50,21 @@ const YAML_MIME_TYPES = [
|
||||
'application/yml'
|
||||
];
|
||||
|
||||
/**
|
||||
* Possible signatures for zip files (which include most modern Microsoft office
|
||||
* documents - most notable excel). If any file, regardless of extension, has
|
||||
* these starting bytes, it's invalid and must be rejected.
|
||||
* For more, see https://en.wikipedia.org/wiki/List_of_file_signatures and
|
||||
* https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files.
|
||||
*
|
||||
* @type String[]
|
||||
*/
|
||||
const ZIP_SIGNATURES = [
|
||||
'PK\u0003\u0004',
|
||||
'PK\u0005\u0006',
|
||||
'PK\u0007\u0008'
|
||||
];
|
||||
|
||||
/*
|
||||
* All file types supported for connection import.
|
||||
*
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
// Save the uploaded data
|
||||
$scope.fileData = e.target.result;
|
||||
$scope.fileData = fileData;
|
||||
|
||||
// Mark the data as ready
|
||||
$scope.dataReady = true;
|
||||
|
@@ -354,12 +354,15 @@ angular.module('import').factory('connectionParseService',
|
||||
parsedData = parseCSVData(csvData, {skip_empty_lines: true});
|
||||
}
|
||||
|
||||
// If the CSV parser throws an error, reject with that error. No
|
||||
// translation key will be available here.
|
||||
// If the CSV parser throws an error, reject with that error
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
const deferred = $q.defer();
|
||||
deferred.reject(new ParseError({ message: error.message }));
|
||||
deferred.reject(new ParseError({
|
||||
message: "CSV Parse Failure: "+ error.message,
|
||||
key: "IMPORT.ERROR_PARSE_FAILURE_CSV",
|
||||
variables: { ERROR: error.message }
|
||||
}));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
@@ -400,12 +403,15 @@ angular.module('import').factory('connectionParseService',
|
||||
connectionData = parseYAMLData(yamlData);
|
||||
}
|
||||
|
||||
// If the YAML parser throws an error, reject with that error. No
|
||||
// translation key will be available here.
|
||||
// If the YAML parser throws an error, reject with that error
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
const deferred = $q.defer();
|
||||
deferred.reject(new ParseError({ message: error.message }));
|
||||
deferred.reject(new ParseError({
|
||||
message: "YAML Parse Failure: "+ error.message,
|
||||
key: "IMPORT.ERROR_PARSE_FAILURE_YAML",
|
||||
variables: { ERROR: error.message }
|
||||
}));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
@@ -434,12 +440,15 @@ angular.module('import').factory('connectionParseService',
|
||||
connectionData = JSON.parse(jsonData);
|
||||
}
|
||||
|
||||
// If the JSON parse attempt throws an error, reject with that error.
|
||||
// No translation key will be available here.
|
||||
// If the JSON parse attempt throws an error, reject with that error
|
||||
catch(error) {
|
||||
console.error(error);
|
||||
const deferred = $q.defer();
|
||||
deferred.reject(new ParseError({ message: error.message }));
|
||||
deferred.reject(new ParseError({
|
||||
message: "JSON Parse Failure: "+ error.message,
|
||||
key: "IMPORT.ERROR_PARSE_FAILURE_JSON",
|
||||
variables: { ERROR: error.message }
|
||||
}));
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
@@ -207,9 +207,13 @@
|
||||
"ERROR_EMPTY_FILE": "The provided file is empty",
|
||||
"ERROR_INVALID_CSV_HEADER": "Invalid CSV Header \"{HEADER}\" is neither an attribute or parameter",
|
||||
"ERROR_INVALID_MIME_TYPE": "Unsupported file type: \"{TYPE}\"",
|
||||
"ERROR_DETECTED_INVALID_TYPE": "Unsupported file type. Please make sure the file is valid CSV, JSON, or YAML.",
|
||||
"ERROR_INVALID_GROUP": "No group matching \"{GROUP}\" found",
|
||||
"ERROR_INVALID_GROUP_IDENTIFIER": "No connection group with identifier \"{IDENTIFIER}\" found",
|
||||
"ERROR_NO_FILE_SUPPLIED": "Please select a file to import",
|
||||
"ERROR_PARSE_FAILURE_CSV": "Please make sure your file is valid CSV. Parsing failed with error \"{ERROR}\". ",
|
||||
"ERROR_PARSE_FAILURE_JSON": "Please make sure your file is valid JSON. Parsing failed with error \"{ERROR}\". ",
|
||||
"ERROR_PARSE_FAILURE_YAML": "Please make sure your file is valid YAML. Parsing failed with error \"{ERROR}\". ",
|
||||
"ERROR_REQUIRED_NAME": "No connection name found in the provided file",
|
||||
"ERROR_REQUIRED_PROTOCOL": "No connection protocol found in the provided file",
|
||||
|
||||
@@ -217,7 +221,7 @@
|
||||
|
||||
"HELP_CSV_DESCRIPTION": "A connection import CSV file has one connection record per row. Each column will specify a connection field. At minimum the connection name and protocol must be specified.",
|
||||
"HELP_CSV_EXAMPLE": "name,protocol,hostname,group,users,groups,guacd-encryption (attribute)\nconn1,vnc,conn1.web.com,ROOT,guac user 1;guac user 2,Connection 1 Users,none\nconn2,rdp,conn2.web.com,ROOT/Parent Group,guac user 1,,ssl\nconn3,ssh,conn3.web.com,ROOT/Parent Group/Child Group,guac user 2;guac user 3,,\nconn4,kubernetes,,,,,",
|
||||
"HELP_CSV_MORE_DETAILS": "The CSV header for each row specifies the connection field. The connection group ID that the connection should be imported into may be directly specified with \"parentIdentifier\", or the path to the parent group may be specified using \"group\" as shown below. In most cases, there should be no conflict between fields, but if needed, an \" (attribute)\" or \" (parameter)\" suffix may be added to disambiguate. Lists of user or user group identifiers must be semicolon-seperated.¹",
|
||||
"HELP_CSV_MORE_DETAILS": "The CSV header for each row specifies the connection field. The connection group ID that the connection should be imported into may be directly specified with \"parentIdentifier\", or the path to the parent group may be specified using \"group\" as shown below. In most cases, there should be no conflict between fields, but if needed, an \" (attribute)\" or \" (parameter)\" suffix may be added to disambiguate. Lists of user or user group identifiers must be semicolon-separated.¹",
|
||||
"HELP_FILE_TYPE_DESCRIPTION": "Three file types are supported for connection import: CSV, JSON, and YAML. The same data may be specified by each file type. This must include the connection name and protocol. Optionally, a connection group location, a list of users and/or user groups to grant access, connection parameters, or connection protocols may also be specified. Any users or user groups that do not exist in the current data source will be automatically created.",
|
||||
"HELP_FILE_TYPE_HEADER": "File Types",
|
||||
"HELP_JSON_DESCRIPTION": "A connection import JSON file is a list of connection objects. At minimum the connection name and protocol must be specified in each connection object.",
|
||||
|
Reference in New Issue
Block a user