fix(ui): render startup messages as text (#4421)

* fix(ui): render startup messages as text

The startup interstitial assigned the /_floci/ui/status "error" field
straight into innerHTML. That text can carry the floci-ui sidecar's own
health JSON (endpoint and error fields) or a Docker daemon exception
message, none of which are trusted markup, so a crafted value could
inject script into the page. Every caller of fail() passes plain
sentences, none of them intend markup, so textContent is the correct
render for all of them.

* test(ui): match the status message assignment, not the whole line
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-09-27 09:38:52 -04:00
1 parent 70c1c407bc
commit 787538997f
2 files changed
+46 -1

No files matched your search

+1 -1
View File
@@ -46,7 +46,7 @@
spinner.style.display = 'none';
title.textContent = 'Floci UI unavailable';
title.className = 'err';
msg.innerHTML = text;
msg.textContent = text;
}
function poll() {
@@ -0,0 +1,45 @@
package io.github.hectorvent.floci.services.floci.ui;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Guards the startup interstitial against HTML/script injection through server-derived error
* text. {@code /_floci/ui/status} forwards {@code error} straight from the floci-ui sidecar's own
* health JSON ({@link FlociUiManager}'s {@code unavailableMessage}) and from Docker daemon
* exception messages, so the polling script in {@code starting.html} must render that text as
* text, never parse it as markup.
*/
class StartingPageEscapesUntrustedTextTest {
private static final Path STARTING_PAGE = Path.of("src", "main", "resources", "ui", "starting.html");
private static final Pattern MSG_HTML_ASSIGNMENT = Pattern.compile("\\bmsg\\.innerHTML\\s*=");
private static final Pattern MSG_TEXT_ASSIGNMENT = Pattern.compile("\\bmsg\\.textContent\\s*=");
@Test
void failRendersServerTextWithoutParsingItAsHtml() {
String content = readStartingPage();
assertFalse(MSG_HTML_ASSIGNMENT.matcher(content).find(),
"starting.html must not assign the status message through innerHTML");
assertTrue(MSG_TEXT_ASSIGNMENT.matcher(content).find(),
"starting.html must render the untrusted status message with textContent");
}
private static String readStartingPage() {
try {
return Files.readString(STARTING_PAGE, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}