Sanitizes frontmatter to prevent data leakage

Introduces sanitization of frontmatter to remove citation fields,
enhancing data privacy and integrity. Adjusts logic to store
sanitized frontmatter in metadata and reconstruct content while
preserving frontmatter when required. Ensures title in metadata
reflects noteTitle when provided.

Enhances frontmatter processing and metadata handling.
This commit is contained in:
AlexKucera committed 2025-11-09 10:51:39 +01:00
1 parent ae5df90eec
commit b0df21d9c2
1 file changed
+11 -10
@@ -51,13 +51,17 @@ export class FrontmatterProcessor {
const parsed = matter(content); const parsed = matter(content);
if (parsed.data && Object.keys(parsed.data).length > 0) { if (parsed.data && Object.keys(parsed.data).length > 0) {
// Replace frontmatter title with filename if noteTitle is provided // Sanitize frontmatter first to prevent citation fields from leaking to downstream consumers
const sanitizedFrontmatter = this.stripCitationFields(parsed.data);
// Store sanitized frontmatter in metadata (with title override if needed)
if (this.noteTitle) { if (this.noteTitle) {
const frontmatterCopy = { ...parsed.data }; result.metadata.frontmatter = {
frontmatterCopy.title = this.noteTitle; ...sanitizedFrontmatter,
result.metadata.frontmatter = frontmatterCopy; title: this.noteTitle
};
} else { } else {
result.metadata.frontmatter = parsed.data; result.metadata.frontmatter = sanitizedFrontmatter;
} }
// Extract tags from frontmatter if they exist // Extract tags from frontmatter if they exist
@@ -92,11 +96,8 @@ export class FrontmatterProcessor {
result.metadata.title = parsed.data.title.trim(); result.metadata.title = parsed.data.title.trim();
} }
// Handle frontmatter preservation and display options // Use the sanitized frontmatter from metadata for writing
const sanitizedFrontmatter = this.stripCitationFields(parsed.data); const finalFrontmatter = result.metadata.frontmatter;
const finalFrontmatter = this.noteTitle ?
{ ...sanitizedFrontmatter, title: this.noteTitle } :
sanitizedFrontmatter;
if (this.preserveFrontmatter) { if (this.preserveFrontmatter) {
// Keep the frontmatter in the content, but reconstruct it with the modified title // Keep the frontmatter in the content, but reconstruct it with the modified title