fix(settings): do not wait 90 s for a restart target on another origin

Since #7205 the page polls its post-restart address before navigating.
When the restart changes the panel's port or turns its TLS on or off, that
address is another origin, and the panel's own CSP (connect-src 'self')
rejects the probe exactly like a refused connection. The poll could never
succeed, so every such restart showed the spinner for the full 90 seconds
although the panel was back after five.

Poll only a same-origin target, which is the reverse-proxy case the wait
was added for. Another origin gets the restart delay alone, as before
#7205. The mixed-content fallback goes with it: its only source was the
http:// target the page used to build behind a TLS proxy.
This commit is contained in:
Sanaei
2026-11-25 17:39:46 +03:30
parent 606d988839
commit d0dc4550c2
2 changed files with 13 additions and 31 deletions
+7 -23
View File
@@ -42,37 +42,21 @@ describe('PromiseUtil.waitForPanel (#7190)', () => {
).resolves.toBe(false);
});
it('probes a new port or protocol with no-cors and accepts the opaque answer', async () => {
// connect-src 'self' rejects the probe like a refused connection, so polling another
// origin could only run to the timeout: 90 s of spinner before a panel that is already up.
it('does not poll a target on another origin, which the page CSP forbids it to reach', async () => {
vi.stubGlobal('window', {
location: {
href: 'http://203.0.113.5:2053/panel/settings',
origin: 'http://203.0.113.5:2053',
},
});
const fetchMock = vi.fn().mockResolvedValue(answer(0, 'opaque'));
const fetchMock = vi.fn().mockRejectedValue(new TypeError('Failed to fetch'));
vi.stubGlobal('fetch', fetchMock);
await expect(
PromiseUtil.waitForPanel('https://203.0.113.5:8443/panel/settings', fast),
).resolves.toBe(true);
expect(fetchMock.mock.calls[0][1]).toMatchObject({ mode: 'no-cors' });
});
it('probes the current origin when an https page would open an http target (mixed content)', async () => {
vi.stubGlobal('window', {
location: {
href: 'https://panel.test/panel/settings',
origin: 'https://panel.test',
protocol: 'https:',
},
});
const fetchMock = vi.fn().mockResolvedValue(answer(200));
vi.stubGlobal('fetch', fetchMock);
await expect(PromiseUtil.waitForPanel('http://panel.test/panel/settings', fast)).resolves.toBe(
true,
);
expect(String(fetchMock.mock.calls[0][0])).toBe('https://panel.test/panel/settings');
expect(fetchMock.mock.calls[0][1]).toMatchObject({ mode: 'same-origin' });
PromiseUtil.waitForPanel('https://203.0.113.5:2053/panel/settings', fast),
).resolves.toBe(false);
expect(fetchMock).not.toHaveBeenCalled();
});
});
+6 -8
View File
@@ -181,27 +181,25 @@ export class PromiseUtil {
});
}
// After the restart delay, polls the target until it answers below 500; false on timeout.
// https page -> http target is blocked as mixed content: probe this origin, the proxy's.
// After the restart delay, polls a same-origin target until it answers below 500; false on
// timeout. connect-src 'self' blocks every other origin, so such a target gets the delay only.
static async waitForPanel(
url: string,
{ delay = 5000, interval = 2000, timeout = 90_000 } = {},
): Promise<boolean> {
await PromiseUtil.sleep(delay);
const target = new URL(url, window.location.href);
const mixed = window.location.protocol === 'https:' && target.protocol === 'http:';
const probe = mixed ? new URL(window.location.href) : target;
const sameOrigin = probe.origin === window.location.origin;
if (target.origin !== window.location.origin) return false;
const deadline = Date.now() + timeout;
while (Date.now() < deadline) {
try {
const res = await fetch(probe, {
const res = await fetch(target, {
cache: 'no-store',
redirect: 'manual',
mode: sameOrigin ? 'same-origin' : 'no-cors',
mode: 'same-origin',
signal: AbortSignal.timeout(Math.max(interval, 1000)),
});
if (res.type === 'opaque' || res.type === 'opaqueredirect' || res.status < 500) return true;
if (res.type === 'opaqueredirect' || res.status < 500) return true;
} catch {
/* not listening yet */
}