Skip to content

Commit 1ceedf2

Browse files
committed
fix(share): missing or protected notes leaking through reference links (closes #4801)
1 parent 416c05e commit 1ceedf2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { getLocaleById } from "../../../services/i18n";
1313
import { getMermaidConfig } from "../../../services/mermaid";
1414
import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./utils";
1515
import { renderMathInElement } from "../../../services/math";
16-
import link from "../../../services/link";
1716
import { formatCodeBlocks } from "../../../services/syntax_highlight";
1817
import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
1918
import appContext from "../../../components/app_context";

apps/server/src/share/content_renderer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ function renderText(result: Result, note: SNote | BNote) {
321321
if (href?.startsWith("#")) {
322322
handleAttachmentLink(linkEl, href, getNote, getAttachment);
323323
}
324+
325+
if (linkEl.classList.contains("reference-link")) {
326+
cleanUpReferenceLinks(linkEl);
327+
}
324328
}
325329

326330
// Apply syntax highlight.
@@ -383,6 +387,25 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: (id: s
383387
}
384388
}
385389

390+
/**
391+
* Processes reference links to ensure that they are up to date. More specifically, reference links contain in their HTML source code the note title at the time of the linking. It can be changed in the mean-time or the note can become protected, which leaks information.
392+
*
393+
* @param linkEl the <a> element to process.
394+
*/
395+
function cleanUpReferenceLinks(linkEl: HTMLElement) {
396+
const noteId = linkEl.getAttribute("href")?.split("/").at(-1);
397+
const note = noteId ? shaca.getNote(noteId) : undefined;
398+
let text = "";
399+
if (!note) {
400+
text = "[missing note]";
401+
} else if (note.isProtected) {
402+
text = "[protected]";
403+
} else {
404+
text = note.title;
405+
}
406+
linkEl.innerHTML = text;
407+
}
408+
386409
/**
387410
* Renders a code note.
388411
*/

0 commit comments

Comments
 (0)