Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: parse allowedHosts arrays whose entries contain brackets (#12688)

[._.]/51714b84ac26
diff --git a/server/lib/viteAllowedHosts.js b/server/lib/viteAllowedHosts.js
index efe88ac2ed..8ae73787db 100644
--- a/server/lib/viteAllowedHosts.js
+++ b/server/lib/viteAllowedHosts.js
@@ -42,8 +42,11 @@ function stripComments(source) {
.replace(/(^|[^:])\/\/[^\n]*/g, '$1');
}
+// The array alternative must skip over quoted strings: an entry like `'[::1]'`
+// contains a `]` that a naive `[^\]]*` would treat as the array's close, leaving
+// the rewrite to splice `true` into the middle of the list and corrupt the file.
const ALLOWED_HOSTS_VALUE_RE =
- /allowedHosts\s*:\s*(true|false|'all'|"all"|`all`|\[[^\]]*\])/;
+ /allowedHosts\s*:\s*(true|false|'all'|"all"|`all`|\[(?:[^\]'"`]|'[^']*'|"[^"]*"|`[^`]*`)*\])/;
/**
* Parse the current `server.allowedHosts` value out of a vite config source.
diff --git a/server/lib/viteAllowedHosts.test.js b/server/lib/viteAllowedHosts.test.js
index b7698bb592..f7d0a678c7 100644
--- a/server/lib/viteAllowedHosts.test.js
+++ b/server/lib/viteAllowedHosts.test.js
@@ -31,6 +31,12 @@ describe('parseAllowedHosts', () => {
expect(p).toMatchObject({ present: true, allowsAll: false, hosts: ['.ts.net', 'localhost'] });
});
+ it('parses an array whose entries contain brackets (bracketed IPv6)', () => {
+ const p = parseAllowedHosts("server: { allowedHosts: ['localhost', '[::1]', '.ts.net'] }");
+ expect(p.hosts).toEqual(['localhost', '[::1]', '.ts.net']);
+ expect(hostIsAllowed(p, 'host.example-tailnet.ts.net')).toBe(true);
+ });
+
it('ignores a commented-out allowedHosts', () => {
const src = `server: {
// allowedHosts: true,
@@ -102,6 +108,13 @@ describe('rewriteAllowedHosts', () => {
expect(out.content).not.toContain("['localhost']");
});
+ it('replaces a whole array containing a bracketed IPv6 entry without leaving remnants', () => {
+ const src = "export default defineConfig({ server: { allowedHosts: ['localhost', '[::1]', 'foo.test'], port: 1 } })";
+ const out = rewriteAllowedHosts(src);
+ expect(out.ok).toBe(true);
+ expect(out.content).toBe("export default defineConfig({ server: { allowedHosts: true, port: 1 } })");
+ });
+
it('replaces allowedHosts: false with true', () => {
const out = rewriteAllowedHosts('server: { allowedHosts: false }');
expect(out.ok).toBe(true);