Skip to content

fix: sanitize error message, escape characters, add nonce, render as innerText [IDE-967]#273

Merged
bastiandoetsch merged 5 commits intomainfrom
fix/sanitize-error-messages-rendered-in-html-panel
Mar 25, 2025
Merged

fix: sanitize error message, escape characters, add nonce, render as innerText [IDE-967]#273
bastiandoetsch merged 5 commits intomainfrom
fix/sanitize-error-messages-rendered-in-html-panel

Conversation

@DariusZdroba
Copy link
Copy Markdown
Contributor

@DariusZdroba DariusZdroba commented Mar 17, 2025

Description

The error messages rendered in Eclipse could potentially contain HTML or scripts which could be rendered as part of the panel ( no resources were accessible through the scripts but still should not happen )

To fix this, the following measures have been applied:

  • Use a Content-Security-Policy in the headers, only scripts which have the randomly set nonce will run.
  • Encode HTML characters with StringEscapeUtils
    image

Checklist

  • Tests added and all succeed
  • Linted
  • CHANGELOG.md updated
  • README.md updated, if user-facing

Screenshots / GIFs

Visuals that may help the reviewer. Please add screenshots for any UI change. GIFs are most welcome!

@DariusZdroba DariusZdroba requested a review from a team as a code owner March 17, 2025 09:09
@DariusZdroba DariusZdroba changed the title fix: sanitize error message, escape characters, add nonce, render as innerText fix: sanitize error message, escape characters, add nonce, render as innerText [IDE-967] Mar 17, 2025
Comment thread plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java Outdated
private final Map<String, String> colorCache = new HashMap<>();
private String nonce = "";

private byte ASCII_RANGE = 0x7F;

Check warning

Code scanning / PMD

Avoid unused private fields such as 'ASCII_RANGE'. Warning

Avoid unused private fields such as 'ASCII_RANGE'.

public String getErrorHtml(String errorMessage, String path) {
var html = """
if (errorMessage == null) errorMessage = "Unknown error";

Check warning

Code scanning / PMD

Avoid reassigning parameters such as 'path' Warning

Avoid reassigning parameters such as 'errorMessage'
public String getErrorHtml(String errorMessage, String path) {
var html = """
if (errorMessage == null) errorMessage = "Unknown error";
if (path == null) path = "Unknown path";

Check warning

Code scanning / PMD

Avoid reassigning parameters such as 'path' Warning

Avoid reassigning parameters such as 'path'
@bastiandoetsch
Copy link
Copy Markdown
Contributor

@DariusZdroba , please fix the linter stuff and then we'll merge it in :)

@bastiandoetsch bastiandoetsch merged commit f214503 into main Mar 25, 2025
8 checks passed
@bastiandoetsch bastiandoetsch deleted the fix/sanitize-error-messages-rendered-in-html-panel branch March 25, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants