mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Remove image HTML elements from non whitelisted sources in Obsidian chat
Given img src enforcement via CSP required loosening. Soft enforce it via a regex replace of img HTML elements if the src isn't from the whitelisted set of source prefixes. Currently allowed source prefixes are - app: for local images - data: for inline generated images - https://generated.khoj.dev: for cloud generated images
This commit is contained in:
parent
c7d825bddb
commit
86a3505d89
1 changed files with 6 additions and 0 deletions
|
@ -322,6 +322,12 @@ export class KhojChatView extends KhojPaneView {
|
|||
// @ts-ignore
|
||||
MarkdownRenderer.renderMarkdown(markdownText, virtualChatMessageBodyTextEl, '', null);
|
||||
|
||||
// Remove image HTML elements with any non whitelisted src prefix
|
||||
virtualChatMessageBodyTextEl.innerHTML = virtualChatMessageBodyTextEl.innerHTML.replace(
|
||||
/<img(?:(?!src=["'](app:|data:|https:\/\/generated\.khoj\.dev)).)*?>/gis,
|
||||
''
|
||||
);
|
||||
|
||||
// Sanitize the markdown text rendered as HTML
|
||||
return DOMPurify.sanitize(virtualChatMessageBodyTextEl.innerHTML);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue