Skip to content
8 changes: 3 additions & 5 deletions packages/web-shell/client/config/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ export function getDaemonToken(): string | undefined {
const fromUrl =
fromHash || new URLSearchParams(window.location.search).get('token') || '';
if (fromUrl) {
// Persist per-tab so the token survives a page refresh (#7301):
// removeDaemonTokenFromUrl() deliberately strips it from the URL for
// history hygiene, which previously left a refreshed page with no
// credential at all. sessionStorage (not localStorage) keeps the token
// scoped to this tab and cleared when the tab closes.
// Persist per-tab so the token survives navigations that do not carry it.
// sessionStorage (not localStorage) keeps the token scoped to this tab and
// cleared when the tab closes.
Comment on lines +50 to +52

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The PR title, description, Reviewer Test Plan, and risk note are stale after commit ca58b2eac — they still claim the token "remains in the URL" (title: "preserve token and base path"; test plan: "confirm the token remains in the URL"; After example: /web-shell/session/new#token=secret; risk: "The token intentionally remains visible in the browser address bar and history"), but the code strips it again (removeDaemonTokenFromUrl() at startup and url.searchParams.delete('token') on every session-URL rewrite, both in non-DEV), so the net change is now only the base-path fix — Failure scenario: a reviewer follows the documented test plan in a production build, opens the shell with ?token=, switches sessions, and observes the token being stripped, contradicting the title, test plan, After-evidence, and the stated security tradeoff.

Suggested fix: update the PR title and description to drop the token-retention claims and reframe the PR as the base-path preservation fix (remove the token-related verification steps, the After example with #token=, and the token-visibility risk note).

中文说明

[Suggestion] PR 标题、描述、Reviewer Test Plan 和风险说明在提交 ca58b2eac 之后已经过时——它们仍声称 token 会“保留在 URL 中”(标题:“preserve token and base path”;测试计划:“confirm the token remains in the URL”;修改后示例:/web-shell/session/new#token=secret;风险:“The token intentionally remains visible in the browser address bar and history”),但代码已恢复移除 token 的逻辑(启动时调用 removeDaemonTokenFromUrl(),每次会话 URL 重写时执行 url.searchParams.delete('token'),均在非 DEV 下),因此当前净改动只剩基础路径保留修复——失败场景:评审者按照文档中的测试计划在生产构建中用 ?token= 打开 Web Shell 并切换会话,观察到 token 被移除,与标题、测试计划、修改后示例以及所述安全取舍相矛盾。

建议修复:更新 PR 标题和描述,去掉 token 保留相关的表述,将 PR 重新定位为基础路径保留修复(删除 token 相关的验证步骤、带 #token= 的修改后示例以及 token 可见性的风险说明)。

— kimi-k3 via Qwen Code /review

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — the PR text is stale. After ca58b2eac the net change is the base-path preservation fix; the token is still stripped (removeDaemonTokenFromUrl() at startup and searchParams.delete('token') on every session-URL rewrite, both in non-DEV), so the title, test plan, After example, and token-visibility risk note no longer match the code.

I have no GitHub credentials and cannot edit the PR title/body from here — the workflow owns network writes. I have written a corrected, reframed pr-title.txt (fix(web-shell): preserve deployment base path in standalone session URLs) and pr-body.md (base-path fix; token handling described as unchanged, with the token-retention verification steps and risk note removed) to the workdir for the workflow/maintainer to apply. Leaving this thread open because I cannot verify the PR text was actually updated.

中文说明

同意——PR 文本确实已过时。在 ca58b2eac 之后,净改动是基础路径保留修复;token 仍会被移除(启动时调用 removeDaemonTokenFromUrl(),每次会话 URL 重写时执行 searchParams.delete('token'),均在非 DEV 下),因此标题、测试计划、修改后示例以及 token 可见性的风险说明已不再与代码相符。

我没有 GitHub 凭据,无法在此处编辑 PR 标题/正文——网络写入由工作流负责。我已将更正后、重新定位的 pr-title.txt(fix(web-shell): preserve deployment base path in standalone session URLs)和 pr-body.md(基础路径修复;将 token 处理描述为未改动,并删除了 token 保留相关的验证步骤和风险说明)写入工作目录,供工作流/维护者应用。该线程保持打开,因为我无法验证 PR 文本是否确实被更新。

persistDaemonToken(fromUrl);
cachedDaemonToken = fromUrl;
return cachedDaemonToken;
Expand Down
9 changes: 5 additions & 4 deletions packages/web-shell/client/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { WorkspaceSessionProvider } from './components/WorkspaceSessionProvider'
import {
getDaemonBaseUrl,
getDaemonToken,
removeDaemonTokenFromUrl,
waitForDaemonTokenMessage,
} from './config/daemon';
import { normalizeLanguage, type WebShellLanguage } from './i18n';
Expand Down Expand Up @@ -98,7 +97,11 @@ function replaceStandaloneSessionUrl(
workspaceId?: string,
): void {
const url = new URL(window.location.href);
url.pathname = sessionId ? `/session/${encodeURIComponent(sessionId)}` : '/';
const sessionPath = url.pathname.match(/^(.*)\/session\/[^/]+\/?$/);
const basePath = sessionPath?.[1] ?? url.pathname.replace(/\/$/, '');
url.pathname = sessionId
? `${basePath}/session/${encodeURIComponent(sessionId)}`
: basePath || '/';
if (sessionId && workspaceId) {
url.searchParams.set('workspace', workspaceId);
} else {
Expand All @@ -110,7 +113,6 @@ function replaceStandaloneSessionUrl(
url.searchParams.delete('language');
url.searchParams.delete('lang');
if (!import.meta.env.DEV) {
url.searchParams.delete('token');
url.searchParams.delete('daemon');
}
window.history.replaceState(null, '', url);
Expand Down Expand Up @@ -182,7 +184,6 @@ function StandaloneApp({ daemonToken }: { daemonToken?: string }) {

async function main() {
const daemonToken = getDaemonToken() ?? (await waitForDaemonTokenMessage());
removeDaemonTokenFromUrl();

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
Expand Down
Loading