fix(session): enforce trusted read scope

This commit is contained in:
Xubin Ren
2026-08-04 12:14:51 +08:00
parent 4c07c40b34
commit f15ea84dd1
11 changed files with 177 additions and 64 deletions
+10 -3
View File
@@ -353,9 +353,14 @@ function fileReferenceFromLink(href: string | undefined): string | null {
}
function sessionReferenceHref(href: string): string | null {
if (!href.startsWith("#/chat/")) return null;
const prefix = href.startsWith("#session/")
? "#session/"
: href.startsWith("#/chat/")
? "#/chat/"
: null;
if (!prefix) return null;
try {
const sessionKey = decodeURIComponent(href.slice("#/chat/".length)).trim();
const sessionKey = decodeURIComponent(href.slice(prefix.length)).trim();
if (!sessionKey.startsWith("websocket:") || sessionKey === "websocket:") return null;
return `#/chat/${encodeURIComponent(sessionKey)}`;
} catch {
@@ -620,7 +625,9 @@ export default function MarkdownTextRenderer({
</a>
);
}
if (href.startsWith("#/chat/")) return <>{markdownChildren}</>;
if (href.startsWith("#/chat/") || href.startsWith("#session/")) {
return <>{markdownChildren}</>;
}
const filePath = fileReferenceFromLink(href);
if (filePath) {
const label = nodeText(markdownChildren).trim();
@@ -16,7 +16,7 @@ describe("MarkdownTextRenderer", () => {
it("renders canonical session references as same-tab links", () => {
render(
<MarkdownTextRenderer>
{"We discussed this in [收费设计](#/chat/websocket%3Apricing)."}
{"We discussed this in [收费设计](#session/websocket%3Apricing)."}
</MarkdownTextRenderer>,
);
@@ -28,7 +28,7 @@ describe("MarkdownTextRenderer", () => {
it("does not link non-WebUI session references", () => {
const { container } = render(
<MarkdownTextRenderer>
{"[private channel](#/chat/telegram%3Aprivate)"}
{"[private channel](#session/telegram%3Aprivate)"}
</MarkdownTextRenderer>,
);