Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

Read a comment in a tenant theme as a comment, not as something the theme defines (#473)

kevin460d2ac525de
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f5caeec..8c37e3a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,18 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
## Unreleased
+### A tenant package's theme may carry a comment
+
+A package's `theme.css` is checked at start-up against what it is allowed to define: the `:root` and
+`.dark` blocks, the approved variables, no imports and no URLs. A CSS comment defines none of those
+and was being read as though it did. One above the blocks — the line a hand-written stylesheet opens
+with, saying whose brand it is and where the colours came from — was left over once the blocks were
+set aside and refused as a second selector; one inside a block was split on the semicolons around it
+and refused as a variable name, with the comment quoted back as the name it was not. Because the
+package is read while the deployment starts, that was not a warning: the deployment did not come up,
+over a comment, saying nothing about comments. Comments are now taken out before the file is read as
+definitions, which also closes a comment wedged into the middle of `url(` as a way past the rule
+above it.
### Test connection stops reading once it has seen the agent answer
The button that checks an agent before it is registered sends it a real run and reads what comes
diff --git a/server/src/tenant-package.ts b/server/src/tenant-package.ts
index 549b51a2..6d991768 100644
--- a/server/src/tenant-package.ts
+++ b/server/src/tenant-package.ts
@@ -51,7 +51,30 @@ const approvedThemeVariables = new Set([
"--sidebar-ring",
]);
-export function validateThemeCss(css: string) {
+export function validateThemeCss(rawCss: string) {
+ /*
+ * A comment is not something a theme defines, so it is taken out before anything below reads the
+ * text as definitions.
+ *
+ * Every rule here is about what a theme may DEFINE — two blocks, approved variables, no imports
+ * and no URLs — and a comment defines nothing. They were applied to the raw file anyway, so a
+ * stylesheet carrying the line every hand-written stylesheet opens with, saying whose brand it is
+ * and where the colours came from, was refused twice over. Above the blocks it survived the
+ * removal of them and read as a second selector: "Tenant theme may only define :root and .dark
+ * blocks". Inside one it was split on the semicolons around it and read as a variable name, so the
+ * refusal quoted the comment back as the variable it was not. A tenant package is loaded at
+ * start-up, so neither of those is a warning: the deployment does not come up, over a comment, and
+ * says nothing about comments.
+ *
+ * Taking them out first is stricter than leaving them in, never weaker. A comment wedged into the
+ * middle of the word `url` makes something a browser does not read as a URL token, and the test
+ * below did not read it as one either; with the comment gone, both do, and it is refused. A
+ * comment that is never closed does not match and is not removed, so it stays as the nonsense it
+ * is and is still refused. What a comment cannot do here is hide anything: what is left once they
+ * are gone is what a browser would act on.
+ */
+ const css = rawCss.replace(/\/\*[\s\S]*?\*\//g, " ");
+
if (/@import|url\s*\(/i.test(css)) {
throw new Error("Tenant theme must not contain imports or URLs");
}
diff --git a/server/tests/tenant-package.test.ts b/server/tests/tenant-package.test.ts
index 819eb555..441e74c1 100644
--- a/server/tests/tenant-package.test.ts
+++ b/server/tests/tenant-package.test.ts
@@ -140,6 +140,60 @@ describe("tenant theme validation", () => {
"is not an approved theme variable",
);
});
+
+ /*
+ * A comment is not something a theme defines.
+ *
+ * The rule this enforces, as `docs/configuration.md` states it, is about what a theme may define:
+ * two blocks, approved variables, no imports and no URLs. A comment defines nothing, and a
+ * stylesheet written by hand has one at the top saying whose brand it is.
+ */
+ test("accepts a comment above the blocks", () => {
+ expect(() =>
+ validateThemeCss(`
+ /* Acme brand colours. Regenerate from the design tokens, do not hand-edit. */
+ :root { --primary: oklch(0.32 0.09 250); }
+ `),
+ ).not.toThrow();
+ });
+
+ test("accepts a comment inside a block", () => {
+ expect(() =>
+ validateThemeCss(`
+ :root {
+ /* The one colour everything else is derived from. */
+ --primary: oklch(0.32 0.09 250);
+ --border: oklch(0.9 0 0); /* deliberately flat */
+ }
+ `),
+ ).not.toThrow();
+ });
+
+ test("accepts a comment between the blocks", () => {
+ expect(() =>
+ validateThemeCss(`
+ :root { --primary: oklch(0.32 0.09 250); }
+ /* and the same again for dark mode */
+ .dark { --primary: oklch(0.87 0.03 250); }
+ `),
+ ).not.toThrow();
+ });
+
+ /*
+ * The guard against over-correcting. A comment must not become a way to smuggle in the two things
+ * this refuses, and a comment that is never closed is not a comment.
+ */
+ test("still refuses what a comment is wrapped around", () => {
+ expect(() =>
+ validateThemeCss(
+ ':root { --primary: url("https://example.com/x.png"); }',
+ ),
+ ).toThrow("must not contain imports or URLs");
+ expect(() => validateThemeCss("/* theme */ body { color: red; }")).toThrow(
+ "only define :root and .dark blocks",
+ );
+ expect(() => validateThemeCss(":root { /* --primary: red; }")).toThrow();
+ });
});
describe("tenant YAML validation", () => {