mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-07 21:08:34 +03:00
fix(session): enforce trusted read scope
This commit is contained in:
@@ -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>,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user