@@ -94,8 +94,9 @@ const authSetup = function () {
9494 } else if ( ! isLoggedIn ( ) && returnAppUrl ) {
9595 login ( ) ;
9696 } else if ( qs [ 'error' ] && qs [ 'state' ] ) {
97- logger ( "Error in executing callback(): " , qs [ 'error_description' ] ) ;
98- showLoginError ( qs [ 'error_description' ] , appUrl ) ;
97+ var error_description = encode ( qs [ 'error_description' ] ) ;
98+ logger ( "Error in executing callback(): " , error_description ) ;
99+ showLoginError ( error_description , appUrl ) ;
99100 } else {
100101 logger ( "User already logged in" , true ) ;
101102 postLogin ( ) ;
@@ -383,6 +384,12 @@ const authSetup = function () {
383384 }
384385 // end token.js
385386
387+ // XSS rules
388+ const encode = function ( str ) {
389+ return str . replace ( / [ \x26 \x0A \< > ' " ] / g, function ( str ) { return "&#" + str . charCodeAt ( 0 ) + ";" } )
390+ }
391+ // end XSS rules
392+
386393 function getHostDomain ( ) {
387394 let hostDomain = "" ;
388395 if ( location . hostname !== 'localhost' ) {
@@ -594,8 +601,10 @@ const authSetup = function () {
594601
595602 function showLoginError ( message , linkUrl ) {
596603 try {
597- document . getElementById ( "page-title-heading" ) . innerHTML = "Alert" ;
598- document . getElementById ( "loading_message_p" ) . innerHTML = message + " <a href=" + linkUrl + ">click here</a>" ;
604+ document . getElementById ( "page-title-heading" ) . innerText = "Alert" ;
605+ var messageElement = document . createElement ( "span" ) ;
606+ messageElement . appendChild ( document . createTextNode ( message ) ) ;
607+ document . getElementById ( "loading_message_p" ) . innerHTML = messageElement . innerText + " <a href=" + linkUrl + ">click here</a>" ;
599608 } catch ( err ) {
600609 logger ( "Error in changing loading message: " , err . message )
601610 }
0 commit comments