@@ -132,7 +132,7 @@ public String replaceCssVariables(String html) {
132
132
133
133
htmlStyled = htmlStyled .replace ("${headerEnd}" , "" );
134
134
htmlStyled = htmlStyled .replace ("${nonce}" , nonce );
135
- htmlStyled = htmlStyled .replace ("ideNonce" , nonce );
135
+ htmlStyled = htmlStyled .replaceAll ("ideNonce" , nonce );
136
136
htmlStyled = htmlStyled .replace ("${ideScript}" , "" );
137
137
138
138
return htmlStyled ;
@@ -207,15 +207,58 @@ public ITheme getCurrentTheme() {
207
207
return currentTheme ;
208
208
}
209
209
210
+ private String escapeHtml (String text ) {
211
+ if (text == null || text .isEmpty ()) {
212
+ return "" ;
213
+ }
214
+ StringBuilder escaped = new StringBuilder ();
215
+ for (char c : text .toCharArray ()) {
216
+ switch (c ) {
217
+ case '&' :
218
+ escaped .append ("&" );
219
+ break ;
220
+ case '<' :
221
+ escaped .append ("<" );
222
+ break ;
223
+ case '>' :
224
+ escaped .append (">" );
225
+ break ;
226
+ case '"' :
227
+ escaped .append (""" );
228
+ break ;
229
+ case '\'' :
230
+ escaped .append ("'" );
231
+ break ;
232
+ case '\n' :
233
+ escaped .append (" " );
234
+ break ;
235
+ case '\r' :
236
+ escaped .append (" " );
237
+ break ;
238
+ default :
239
+ if (c > 0x7F ) {
240
+ escaped .append ("&#" ).append ((int ) c ).append (";" );
241
+ } else {
242
+ escaped .append (c );
243
+ }
244
+ break ;
245
+ }
246
+ }
247
+ return escaped .toString ();
248
+ }
210
249
public String getErrorHtml (String errorMessage , String path ) {
250
+ String escapedErrorMessage = escapeHtml (errorMessage );
251
+ String escapedPath = escapeHtml (path );
211
252
var html = """
212
253
<!DOCTYPE html>
213
254
<html lang="en">
214
255
<head>
256
+ <meta http-equiv='Content-Type' content='text/html; charset=unicode' />
215
257
<meta charset="UTF-8">
216
258
<meta name="viewport" content="width=device-width, initial-scale=1.0">
259
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-ideNonce'; style-src 'self' 'nonce-ideNonce';">
217
260
<title>Snyk for Eclipse</title>
218
- <style>
261
+ <style nonce=ideNonce >
219
262
body {
220
263
font-family: var(--default-font);
221
264
background-color: var(--background-color);
@@ -236,16 +279,23 @@ public String getErrorHtml(String errorMessage, String path) {
236
279
<p><strong>An error occurred:</strong></p>
237
280
<p>
238
281
<table>
239
- <tr><td width="150" >Error message:</td><td>%s </td></tr>
282
+ <tr><td width="150" >Error message:</td><td id="errorContainer"> </td></tr>
240
283
<tr></tr>
241
- <tr><td>Path:</td><td>%s </td></tr>
284
+ <tr><td width="150" >Path:</td><td id="pathContainer"> </td></tr>
242
285
</table>
243
286
</p>
244
287
</div>
245
288
</div>
246
289
</body>
290
+ <script nonce=ideNonce>
291
+ const errMsgElement = document.getElementById("errorContainer");
292
+ errMsgElement.innerText = "%s";
293
+ const pathElem = document.getElementById("pathContainer");
294
+ pathElem.innerText = "%s";
295
+ </script>
247
296
</html>
248
- """ .formatted (errorMessage , path );
297
+ """ .formatted (escapedErrorMessage , escapedPath );
298
+ System .out .print (html );
249
299
return replaceCssVariables (html );
250
300
}
251
301
}
0 commit comments