Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Summary, notes and Inquire messages never rendered from raw text (#439)
Murtaza Nasir05c964a2b20b
diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 7850893e..9c6c6aea 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -3558,6 +3558,19 @@ document.addEventListener('DOMContentLoaded', async () => {return window.renderMarkdownSafe(customBanner.value);});+ // Summary and notes of the open recording. The server's sanitized+ // HTML is used when present; without it (a summary saved in this+ // tab, an incognito recording) the markdown is rendered here and+ // sanitized. The raw text is never used as HTML (#439).+ const renderedField = (field) => {+ const rec = selectedRecording.value;+ if (!rec) return '';+ if (rec[field + '_html']) return rec[field + '_html'];+ return rec[field] ? window.renderMarkdownSafe(rec[field]) : '';+ };+ const summaryHtml = computed(() => renderedField('summary'));+ const notesHtml = computed(() => renderedField('notes'));+// Get tag prompt previewconst getTagPromptPreview = (tagId) => {const tag = availableTags.value.find(t => t.id == tagId);@@ -4404,6 +4417,8 @@ document.addEventListener('DOMContentLoaded', async () => {...state,// Computed+ summaryHtml,+ notesHtml,isMobileScreen,isMobileDevice,processedTranscription,diff --git a/templates/components/detail/desktop-notes-tab.html b/templates/components/detail/desktop-notes-tab.htmlindex 353be272..0190e5fa 100644--- a/templates/components/detail/desktop-notes-tab.html+++ b/templates/components/detail/desktop-notes-tab.html@@ -8,8 +8,8 @@<div v-if="!editingNotes"class="flex-1 overflow-y-auto px-4 py-4 prose-flush"@click="clickToEditNotes">- <div v-if="selectedRecording.notes_html"- v-html="selectedRecording.notes_html">+ <div v-if="notesHtml"+ v-html="notesHtml"></div><div v-else-if="selectedRecording.notes" class="whitespace-pre-wrap">${selectedRecording.notes}diff --git a/templates/components/detail/desktop-summary-tab.html b/templates/components/detail/desktop-summary-tab.htmlindex 1fe9c942..7422cdf9 100644--- a/templates/components/detail/desktop-summary-tab.html+++ b/templates/components/detail/desktop-summary-tab.html@@ -48,7 +48,7 @@is inside so the scrollbar runs the full edge. --><div v-else-if="!editingSummary"class="flex-1 overflow-y-auto px-4 py-4 prose-flush"- v-html="selectedRecording.summary_html || selectedRecording.summary">+ v-html="summaryHtml"></div><!-- Editing mode — EasyMDE is mounted onto the textarea below.diff --git a/templates/components/detail/mobile-notes-panel.html b/templates/components/detail/mobile-notes-panel.htmlindex 34953a50..4f17029f 100644--- a/templates/components/detail/mobile-notes-panel.html+++ b/templates/components/detail/mobile-notes-panel.html@@ -27,6 +27,6 @@<div class="empty__title" v-text="t('help.clickToAddNotes')"></div><div class="empty__body">Markdown supported.</div></div>- <div v-else class="prose-flush h-full" v-html="selectedRecording.notes_html || selectedRecording.notes"></div>+ <div v-else class="prose-flush h-full" v-html="notesHtml"></div></div></div>diff --git a/templates/components/detail/mobile-summary-panel.html b/templates/components/detail/mobile-summary-panel.htmlindex 3aae84b5..082906ae 100644--- a/templates/components/detail/mobile-summary-panel.html+++ b/templates/components/detail/mobile-summary-panel.html@@ -59,7 +59,7 @@</button></div></div>- <div v-else class="prose-flush h-full" v-html="selectedRecording.summary_html || selectedRecording.summary"></div>+ <div v-else class="prose-flush h-full" v-html="summaryHtml"></div></div></div></div>diff --git a/templates/inquire.html b/templates/inquire.htmlindex 21389be2..28bbc518 100644--- a/templates/inquire.html+++ b/templates/inquire.html@@ -501,7 +501,7 @@<div v-if="message.html || message.content"class="prose prose-sm max-w-none":class="message.role === 'user' ? 'prose-invert' : ''"- v-html="message.html || message.content">+ v-html="message.html"></div></div></div>@@ -829,6 +829,13 @@}};+ // A typed question is shown as text, never as HTML (#439).+ const escapeHtml = (text) => {+ const div = document.createElement('div');+ div.textContent = text;+ return div.innerHTML;+ };+// Rewrite citation links into numbered chips plus a// trailing Sources list. The model emits// [Title @ m:ss](/recordings/<id>?t=s); repeating the full@@ -955,7 +962,7 @@if (!inquireChatInput.value.trim() || isInquireChatLoading.value) return;const userMessage = inquireChatInput.value.trim();- inquireChatMessages.value.push({ role: 'user', content: userMessage, html: userMessage });+ inquireChatMessages.value.push({ role: 'user', content: userMessage, html: escapeHtml(userMessage) });inquireChatInput.value = '';isInquireChatLoading.value = true;showProcessingStatus.value = true;diff --git a/tests/test_vhtml_raw_fields.py b/tests/test_vhtml_raw_fields.pynew file mode 100644index 00000000..62327eaa--- /dev/null+++ b/tests/test_vhtml_raw_fields.py@@ -0,0 +1,28 @@+"""No raw summary, notes or message text is assigned to v-html (#439).++The templates used ``summary_html || summary``: when the sanitizer removed a+payload entirely, the empty string fell through to the raw stored text, which+was then rendered as HTML.+"""++import os+import re++ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+RAW_FIELD = re.compile(r'\.(summary|notes|content|transcription)\b(?!_html)')+++def _v_html_expressions():+ for folder, _, files in os.walk(os.path.join(ROOT, 'templates')):+ for name in files:+ if not name.endswith('.html'):+ continue+ path = os.path.join(folder, name)+ with open(path, encoding='utf-8') as f:+ for expr in re.findall(r'v-html="([^"]*)"', f.read()):+ yield os.path.relpath(path, ROOT), expr+++def test_no_raw_field_reaches_v_html():+ offenders = [(p, e) for p, e in _v_html_expressions() if RAW_FIELD.search(e)]+ assert not offenders