From 53482194501c10b9d4199577f046d20e5ad61edd Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Thu, 16 Jun 2022 13:15:12 +0200 Subject: [PATCH] Fix some XSS There was an issue with election description. During election creation, we relied in ng-bind-html to sanitize the visualization of election description before being sanitized by the backend (because it has not yet been sent to the backend), but apparently it doesn't work for some xss. The same issue happened in election list when showing the description of the drafti election. With this change, we always show the election description as plain text so that we don't need to sanitize it. Also see related issue with htmlToText in common-ui: https://github.com/sequentech/common-ui/pull/221 because sometimes we also called to our own htmlToText angular filter, and sanitization was also needed to happen there. Another fix is to use $sanitize more pervasively in the election creation screen, so that any reply from the server is also not trusted and properly sanitized. --- avAdmin/admin-directives/create/create.html | 2 +- avAdmin/admin-directives/create/create.js | 9 +++++---- avAdmin/admin-directives/elections/elections.html | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/avAdmin/admin-directives/create/create.html b/avAdmin/admin-directives/create/create.html index 4f2b86fd..c14c05c9 100644 --- a/avAdmin/admin-directives/create/create.html +++ b/avAdmin/admin-directives/create/create.html @@ -9,7 +9,7 @@

[i18next]({'title': election.title, 'index': $index+1})avAdmin.ba - + diff --git a/avAdmin/admin-directives/create/create.js b/avAdmin/admin-directives/create/create.js index 6e07850b..68000293 100644 --- a/avAdmin/admin-directives/create/create.js +++ b/avAdmin/admin-directives/create/create.js @@ -26,6 +26,7 @@ angular.module('avAdmin') ElectionsApi, $state, $stateParams, + $sanitize, $i18next, $filter, $modal, @@ -69,11 +70,11 @@ angular.module('avAdmin') } function logInfo(text) { - scope.log += "

" + text + "

"; + scope.log += "

" + $sanitize(text) + "

"; } function logError(text) { - scope.log += "

" + text + "

"; + scope.log += "

" + $sanitize(text) + "

"; } function validateEmail(email) { var re = /^[^\s@]+@[^\s@.]+\.[^\s@.]+$/; @@ -1078,7 +1079,7 @@ angular.module('avAdmin') election: el, error: function (errorMsg) { scope.errors.push({ - data: {message: errorMsg}, + data: {message: $sanitize($sanitize)(errorMsg)}, key: "election-census-createel-unknown" }); }, @@ -1316,7 +1317,7 @@ angular.module('avAdmin') data: scope.elections, onError: function (errorKey, errorData) { scope.errors.push({ - data: errorData, + data: $sanitize(errorData), key: errorKey }); } diff --git a/avAdmin/admin-directives/elections/elections.html b/avAdmin/admin-directives/elections/elections.html index da7f22db..fe58db03 100644 --- a/avAdmin/admin-directives/elections/elections.html +++ b/avAdmin/admin-directives/elections/elections.html @@ -84,7 +84,7 @@

{{ draft.title }}
+ ng-bind="draft.description | htmlToText | truncate:150">
@@ -122,7 +122,7 @@

{{ election.title }}
+ ng-bind="election.description | htmlToText | truncate:150">
@@ -142,7 +142,7 @@

{{ childElection.title }}
+ ng-bind="childElection.description | htmlToText | truncate:150">

avAdmin.basic.description.label
avAdmin.sidebar.questions