diff --git a/admin/js/admin-scripts.js b/admin/js/admin-scripts.js index 09d8711..725c722 100644 --- a/admin/js/admin-scripts.js +++ b/admin/js/admin-scripts.js @@ -105,10 +105,16 @@ * @param {string} message Notice message */ showNotice: function (type, message) { - const $notice = $( '

' + message + '

' ); + const allowedTypes = [ 'success', 'error', 'warning' ]; + const safeType = allowedTypes.includes( type ) ? type : 'error'; + const $p = $( '

' ); + const $notice = $( '

' ).addClass( 'wpst-notice ' + safeType ).append( $p ); + + // Set message as plain text to prevent XSS. + $p.text( message ); // Add notice to the page. - $( '.wpst-notices' ).html( $notice ); + $( '.wpst-notices' ).empty().append( $notice ); // Automatically remove notice after 5 seconds. setTimeout( diff --git a/admin/js/update-source-selector.js b/admin/js/update-source-selector.js index 5f21f36..3b2c1da 100644 --- a/admin/js/update-source-selector.js +++ b/admin/js/update-source-selector.js @@ -153,8 +153,8 @@ showMessage: function (type, message) { const $message = this.$modal.find( '.wpst-modal-message' ); - // Set message content and type. - $message.html( message ).removeClass( 'success error' ).addClass( type ).show(); + // Set message as plain text to prevent XSS, then apply type class. + $message.text( message ).removeClass( 'success error' ).addClass( type ).show(); // Hide message after a delay for success messages. if (type === 'success') { diff --git a/admin/templates/modal.php b/admin/templates/modal.php index ad59744..7fbfd78 100644 --- a/admin/templates/modal.php +++ b/admin/templates/modal.php @@ -12,11 +12,11 @@ if ( ! defined( 'ABSPATH' ) ) { ?> -
+