diff --git a/public/js/views/document.js b/public/js/views/document.js index 4106cb5..7988f6e 100644 --- a/public/js/views/document.js +++ b/public/js/views/document.js @@ -81,6 +81,9 @@ export async function renderDocument(app) { `; window.filterByTag = (tag) => { + // Store the tag to filter by in app state so dashboard can pick it up + app.state.selectedTag = tag; + app.state.selectedLibrary = null; app.navigate('dashboard'); }; } @@ -94,7 +97,12 @@ export async function renderDocument(app) { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = `${doc.id}-${doc.title}.md`; + // Sanitize filename to prevent path traversal + const safeFilename = (doc.title || 'untitled') + .replace(/[^a-zA-Z0-9_\-\s]/g, '') + .replace(/\s+/g, '-') + .substring(0, 100); + a.download = `${doc.id}-${safeFilename}.md`; a.click(); URL.revokeObjectURL(url); app.showToast('Document exported', 'success');