44import java .util .Map ;
55import java .util .Random ;
66
7+ import org .apache .commons .text .StringEscapeUtils ;
78import org .eclipse .core .runtime .Platform ;
89import org .eclipse .jface .resource .ColorRegistry ;
910import org .eclipse .jface .resource .JFaceResources ;
@@ -22,7 +23,6 @@ public class BaseHtmlProvider {
2223 private final Random random = new Random ();
2324 private final Map <String , String > colorCache = new HashMap <>();
2425 private String nonce = "" ;
25-
2626 public String getCss () {
2727 return "" ;
2828 }
@@ -132,7 +132,7 @@ public String replaceCssVariables(String html) {
132132
133133 htmlStyled = htmlStyled .replace ("${headerEnd}" , "" );
134134 htmlStyled = htmlStyled .replace ("${nonce}" , nonce );
135- htmlStyled = htmlStyled .replace ("ideNonce" , nonce );
135+ htmlStyled = htmlStyled .replaceAll ("ideNonce" , nonce );
136136 htmlStyled = htmlStyled .replace ("${ideScript}" , "" );
137137
138138 return htmlStyled ;
@@ -206,16 +206,19 @@ public ITheme getCurrentTheme() {
206206 currentTheme = themeManager .getCurrentTheme ();
207207 return currentTheme ;
208208 }
209-
210209 public String getErrorHtml (String errorMessage , String path ) {
211- var html = """
210+ String escapedErrorMessage = errorMessage == null ? "Unknown error" : StringEscapeUtils .escapeHtml3 ((errorMessage ));
211+ String escapedPath = path == null ? "Unknown path" : StringEscapeUtils .escapeHtml3 (path );
212+ var html = String .format ("""
212213 <!DOCTYPE html>
213214 <html lang="en">
214215 <head>
216+ <meta http-equiv='Content-Type' content='text/html; charset=unicode' />
215217 <meta charset="UTF-8">
216218 <meta name="viewport" content="width=device-width, initial-scale=1.0">
219+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-ideNonce'; style-src 'self' 'nonce-ideNonce';">
217220 <title>Snyk for Eclipse</title>
218- <style>
221+ <style nonce=ideNonce >
219222 body {
220223 font-family: var(--default-font);
221224 background-color: var(--background-color);
@@ -236,16 +239,16 @@ public String getErrorHtml(String errorMessage, String path) {
236239 <p><strong>An error occurred:</strong></p>
237240 <p>
238241 <table>
239- <tr><td width="150" >Error message:</td><td>%s</td></tr>
242+ <tr><td width="150" >Error message:</td><td id="errorContainer" >%s</td></tr>
240243 <tr></tr>
241- <tr><td>Path:</td><td>%s</td></tr>
244+ <tr><td width="150" >Path:</td><td id="pathContainer" >%s</td></tr>
242245 </table>
243246 </p>
244247 </div>
245248 </div>
246249 </body>
247250 </html>
248- """ . formatted ( errorMessage , path );
251+ """ , escapedErrorMessage , escapedPath );
249252 return replaceCssVariables (html );
250253 }
251254}
0 commit comments