diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java b/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java index 72e70a1497..c76117ffd6 100644 --- a/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java +++ b/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java @@ -16,9 +16,10 @@ import jakarta.ws.rs.core.Response; * Browser-facing endpoints that launch and redirect to the floci-ui sidecar. * * */ @@ -38,7 +39,7 @@ public class UiController { @Produces(MediaType.TEXT_HTML) public Response ui() { uiManager.ensureStartedAsync(); - return Response.ok(uiPages.startingHtml()).build(); + return Response.ok(uiPages.landingHtml()).build(); } @RegisterForReflection diff --git a/src/main/java/io/github/hectorvent/floci/services/floci/ui/UiPages.java b/src/main/java/io/github/hectorvent/floci/services/floci/ui/UiPages.java index 1b6da98c68..c2f25993b4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/floci/ui/UiPages.java +++ b/src/main/java/io/github/hectorvent/floci/services/floci/ui/UiPages.java @@ -7,20 +7,18 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; /** - * Loads and caches the small embedded HTML pages served to browsers: the Floci - * landing page and the "starting the UI" interstitial. Resources are read from - * the classpath ({@code ui/*.html}) and must be registered in - * {@code quarkus.native.resources.includes} so they are embedded in the native - * image. + * Loads and caches the embedded HTML page served to browsers. One file holds two + * views, the dashboard and the "starting the UI" wait view, and picks between them + * from the request path. It is read from the classpath ({@code ui/*.html}) and must + * be registered in {@code quarkus.native.resources.includes} so it is embedded in + * the native image. */ @ApplicationScoped public class UiPages { private static final String LANDING_RESOURCE = "ui/index.html"; - private static final String STARTING_RESOURCE = "ui/starting.html"; private volatile String landing; - private volatile String starting; public String landingHtml() { String result = landing; @@ -31,15 +29,6 @@ public class UiPages { return result; } - public String startingHtml() { - String result = starting; - if (result == null) { - result = readResource(STARTING_RESOURCE); - starting = result; - } - return result; - } - private static String readResource(String resourceName) { ClassLoader loader = UiPages.class.getClassLoader(); try (InputStream input = loader.getResourceAsStream(resourceName)) { diff --git a/src/main/resources/ui/index.html b/src/main/resources/ui/index.html index c40209e9f4..98f8d486ef 100644 --- a/src/main/resources/ui/index.html +++ b/src/main/resources/ui/index.html @@ -3,287 +3,780 @@ - Floci — local AWS emulator + Floci: local AWS emulator + - + -
-
- - - connecting… - -
-

Any cloud. Locally. — a local AWS emulator speaking real AWS wire protocols.

-

You've reached the Floci endpoint. Point your AWS SDK or CLI here with - --endpoint-url http://localhost:4566 and it behaves like AWS.

-
-
Endpoint
http://localhost:4566
-
Region
us-east-1 (default)
-
Account
000000000000
-
Version
…
-
-
-
-

Services

- — running · — available +
+ + + + + Connecting… + + + +
+
+ +
+
+
+

Connect

+

Point any AWS SDK or CLI at this endpoint and it behaves like AWS. Any credentials work.

+
+
Endpoint
+
Region
us-east-1
+
Account
000000000000
+
+
+ + + +
- -
-
Loading services…
+
+

       
-
- - Open Floci UI → - -

The UI launches on demand as a sidecar container the first time you open it. -  ·  health · info

-
+
- + } + start(); + })(); + diff --git a/src/main/resources/ui/starting.html b/src/main/resources/ui/starting.html deleted file mode 100644 index acf09cc5cf..0000000000 --- a/src/main/resources/ui/starting.html +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - Starting Floci UI… - - - -
-
-

Starting Floci UI…

-

Launching the UI container. This can take a moment the first time while the image is pulled.

-
- - - diff --git a/src/test/java/io/github/hectorvent/floci/services/floci/ui/StartingPageEscapesUntrustedTextTest.java b/src/test/java/io/github/hectorvent/floci/services/floci/ui/StartingPageEscapesUntrustedTextTest.java index 3e3b87c371..34fe84fbeb 100644 --- a/src/test/java/io/github/hectorvent/floci/services/floci/ui/StartingPageEscapesUntrustedTextTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/floci/ui/StartingPageEscapesUntrustedTextTest.java @@ -13,31 +13,43 @@ 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 + * Guards the landing page 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. + * exception messages, so both views of {@code index.html} must render that text as text, never + * parse it as markup: the wait view through {@code textContent}, the dashboard through + * {@code escapeHtml}. */ 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*="); + private static final Path LANDING_PAGE = Path.of("src", "main", "resources", "ui", "index.html"); + private static final Pattern ERROR_HTML_ASSIGNMENT = Pattern.compile("\\(\"launch-error\"\\)\\.innerHTML\\s*="); + private static final Pattern ERROR_TEXT_ASSIGNMENT = Pattern.compile("\\(\"launch-error\"\\)\\.textContent\\s*="); + private static final Pattern RAW_ERROR_CONCATENATION = Pattern.compile("\\+\\s*(?:ui|s)\\.error\\b"); @Test void failRendersServerTextWithoutParsingItAsHtml() { - String content = readStartingPage(); + String content = readLandingPage(); - 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"); + assertFalse(ERROR_HTML_ASSIGNMENT.matcher(content).find(), + "index.html must not assign the launch error through innerHTML"); + assertTrue(ERROR_TEXT_ASSIGNMENT.matcher(content).find(), + "index.html must render the untrusted launch error with textContent"); } - private static String readStartingPage() { + @Test + void dashboardEscapesServerTextBeforeConcatenatingItIntoHtml() { + String content = readLandingPage(); + + assertFalse(RAW_ERROR_CONCATENATION.matcher(content).find(), + "index.html must not concatenate the status error into markup unescaped"); + assertTrue(content.contains("escapeHtml(ui.error)"), + "index.html must escape the status error shown in the Runtime block"); + } + + private static String readLandingPage() { try { - return Files.readString(STARTING_PAGE, StandardCharsets.UTF_8); + return Files.readString(LANDING_PAGE, StandardCharsets.UTF_8); } catch (IOException e) { throw new UncheckedIOException(e); }