mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(webview): keep dashboard cookies alongside the injected one
The managed DeepSeek tab is trusted, so the browser's own cookies for the dashboard are forwarded. The injected dsh credential replaced that header instead of joining it, dropping any other cookie dsh had set. Append the pair to the filtered browser cookies and leave the rest untouched.
This commit is contained in:
1 parent
7f729ee87b
commit
238853f96a
4 files changed
+36
-14
No files matched your search
@@ -2,4 +2,4 @@
|
||||
"aicodeman": patch
|
||||
---
|
||||
|
||||
The DeepSeek Harness web tab opens on the dashboard again instead of a blank 401 page. `dsh web` now gates its own index behind a one-time launch token it prints on boot; the supervisor reads that token out of the captured output, trades it for the session cookie once at startup, and the webview proxy presents the cookie on both the HTTP and WebSocket legs — scoped to the loopback authority it was minted for. The banner reader scans every `dsh web:` line (diagnostics share the prefix) and only complete lines (a split write is waited for), so a `dsh web: loading profiles` line no longer makes boot give up. The printed token URL is only fetched when it names `127.0.0.1` on the port that was just spawned. A server whose exchange failed is no longer reused, so asking to start the UI again restarts it and retries the exchange. The cookie is only presented to a tab whose owner holds the privileged-commands grant, and in multi-user mode only to the owner whose request started the process: `managed` is a client-supplied field and the live port is public, so the saved record alone is not an entitlement. A dsh without the gate keeps working unchanged.
|
||||
The DeepSeek Harness web tab opens on the dashboard again instead of a blank 401 page. `dsh web` now gates its own index behind a one-time launch token it prints on boot; the supervisor reads that token out of the captured output, trades it for the session cookie once at startup, and the webview proxy presents the cookie on both the HTTP and WebSocket legs — scoped to the loopback authority it was minted for. It is appended to the dashboard's own cookies rather than replacing them. The banner reader scans every `dsh web:` line (diagnostics share the prefix) and only complete lines (a split write is waited for), so a `dsh web: loading profiles` line no longer makes boot give up. The printed token URL is only fetched when it names `127.0.0.1` on the port that was just spawned. A server whose exchange failed is no longer reused, so asking to start the UI again restarts it and retries the exchange. The cookie is only presented to a tab whose owner holds the privileged-commands grant, and in multi-user mode only to the owner whose request started the process: `managed` is a client-supplied field and the live port is public, so the saved record alone is not an entitlement. A dsh without the gate keeps working unchanged.
|
||||
@@ -315,7 +315,9 @@ proxy presents the cookie only when the tab's owner holds the same
|
||||
privileged-commands grant `POST /api/deepseek/web` requires, and in multi-user mode
|
||||
only to the owner whose request started that process. A different owner's start
|
||||
request restarts the server rather than reusing a cookie that is not theirs, which
|
||||
is why the shared instance is effectively single-user at a time.
|
||||
is why the shared instance is effectively single-user at a time. On a trusted
|
||||
managed tab the cookie is appended to whatever cookies dsh itself set in the
|
||||
browser, rather than replacing them.
|
||||
|
||||
## 7. Docker and remote cases
|
||||
|
||||
|
||||
@@ -384,10 +384,12 @@ export function buildUpstreamRequestHeaders(
|
||||
refererPath?: string;
|
||||
relayBodyLength?: boolean;
|
||||
/**
|
||||
* A credential the SERVER holds for this dashboard, replacing whatever the
|
||||
* browser sent. `dsh web` mints its session cookie for a loopback authority
|
||||
* the browser never visits, so the proxy is the only party that can present
|
||||
* it (see `deepseek-web-server.ts`).
|
||||
* A credential the SERVER holds for this dashboard, appended to whatever
|
||||
* browser cookies were forwarded. `dsh web` mints its session cookie for a
|
||||
* loopback authority the browser never visits, so the proxy is the only party
|
||||
* that can present it (see `deepseek-web-server.ts`); the managed tab is
|
||||
* trusted, which means the browser may also carry other cookies dsh set, and
|
||||
* those must survive.
|
||||
*/
|
||||
injectedCookie?: string;
|
||||
}
|
||||
@@ -422,10 +424,14 @@ export function buildUpstreamRequestHeaders(
|
||||
if (cookie) headers['cookie'] = cookie;
|
||||
}
|
||||
|
||||
// After the relay above, so a browser copy can never shadow it: these cookies
|
||||
// are scoped to the browser's origin, and the authority this request is for is
|
||||
// one it has never been able to store anything against.
|
||||
if (opts.injectedCookie) headers['cookie'] = opts.injectedCookie;
|
||||
// Appended after the relay above, so a browser copy can never shadow it: this
|
||||
// cookie is scoped to the authority the request is for, one the browser has
|
||||
// never been able to store anything against. Other cookies are kept: a managed
|
||||
// dsh tab is trusted, so dsh's own non-auth cookies may legitimately be there.
|
||||
if (opts.injectedCookie) {
|
||||
const existing = headers['cookie'];
|
||||
headers['cookie'] = existing ? `${existing}; ${opts.injectedCookie}` : opts.injectedCookie;
|
||||
}
|
||||
|
||||
// Present as if the browser were talking to the dashboard directly. Apps that
|
||||
// check Origin on writes (CSRF defenses) need this to match their own origin.
|
||||
|
||||
@@ -241,14 +241,28 @@ describe('buildUpstreamRequestHeaders', () => {
|
||||
|
||||
// `dsh web` mints its session cookie for the loopback authority the proxy
|
||||
// dials, which the browser has never visited and cannot store anything for.
|
||||
// The supervisor holds it instead, and it must win over the browser's copy.
|
||||
it('replaces the browser cookies with a server-held credential', () => {
|
||||
const headers = buildUpstreamRequestHeaders({ cookie: 'codeman_session=SECRET; stale=1' }, upstream, {
|
||||
// The supervisor holds it instead. The managed tab is trusted, so the browser's
|
||||
// other dsh cookies are still present and must be kept alongside it.
|
||||
it('appends the server-held credential to the filtered browser cookies', () => {
|
||||
const headers = buildUpstreamRequestHeaders({ cookie: 'codeman_session=SECRET; dash=1' }, upstream, {
|
||||
forwardCookies: true,
|
||||
sessionCookieName: 'codeman_session',
|
||||
injectedCookie: 'dsh-auth-p=v1.payload.sig',
|
||||
});
|
||||
expect(headers.cookie).toBe('dsh-auth-p=v1.payload.sig');
|
||||
expect(headers.cookie).toBe('dash=1; dsh-auth-p=v1.payload.sig');
|
||||
});
|
||||
|
||||
it('keeps every non-Codeman browser cookie when injecting the server credential', () => {
|
||||
const headers = buildUpstreamRequestHeaders(
|
||||
{ cookie: 'dsh-ui=dark; codeman_session=SECRET; dsh-settings=z' },
|
||||
upstream,
|
||||
{
|
||||
forwardCookies: true,
|
||||
sessionCookieName: 'codeman_session',
|
||||
injectedCookie: 'dsh-auth-p=v1.payload.sig',
|
||||
}
|
||||
);
|
||||
expect(headers.cookie).toBe('dsh-ui=dark; dsh-settings=z; dsh-auth-p=v1.payload.sig');
|
||||
});
|
||||
|
||||
it('sends the server-held credential even when browser cookies are not forwarded', () => {
|
||||
|
||||
Reference in new issue
Block a user