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:
1 file changed
+16
-15
@@ -51,19 +51,23 @@ 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
|
||||||
if (parsed.data.tags) {
|
if (parsed.data.tags) {
|
||||||
let frontmatterTags: string[] = [];
|
let frontmatterTags: string[] = [];
|
||||||
|
|
||||||
if (Array.isArray(parsed.data.tags)) {
|
if (Array.isArray(parsed.data.tags)) {
|
||||||
// Handle array of tags
|
// Handle array of tags
|
||||||
frontmatterTags = parsed.data.tags
|
frontmatterTags = parsed.data.tags
|
||||||
@@ -76,7 +80,7 @@ export class FrontmatterProcessor {
|
|||||||
.map((tag: string) => tag.trim())
|
.map((tag: string) => tag.trim())
|
||||||
.filter((tag: string) => tag !== '');
|
.filter((tag: string) => tag !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge with existing tags (avoid duplicates)
|
// Merge with existing tags (avoid duplicates)
|
||||||
for (const tag of frontmatterTags) {
|
for (const tag of frontmatterTags) {
|
||||||
if (!result.metadata.tags.includes(tag)) {
|
if (!result.metadata.tags.includes(tag)) {
|
||||||
@@ -84,19 +88,16 @@ export class FrontmatterProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract title - use noteTitle if available, otherwise frontmatter title
|
// Extract title - use noteTitle if available, otherwise frontmatter title
|
||||||
if (this.noteTitle) {
|
if (this.noteTitle) {
|
||||||
result.metadata.title = this.noteTitle;
|
result.metadata.title = this.noteTitle;
|
||||||
} else if (parsed.data.title && typeof parsed.data.title === 'string') {
|
} else if (parsed.data.title && typeof parsed.data.title === 'string') {
|
||||||
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
|
||||||
|
|||||||
Reference in new issue
Block a user