mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 19:19:03 +01:00 
			
		
		
		
	respect safeImport flag when sanitizing imported content
This commit is contained in:
		
							parent
							
								
									692f7868bc
								
							
						
					
					
						commit
						90c0a4a437
					
				| @ -33,17 +33,7 @@ function sanitize(dirtyHtml) { | |||||||
|             'en-media' // for ENEX import
 |             'en-media' // for ENEX import
 | ||||||
|         ], |         ], | ||||||
|         allowedAttributes: { |         allowedAttributes: { | ||||||
|             'a': [ 'href', 'class' ], |             '*': [ 'class', 'style', 'title', 'src', 'href', 'hash', 'disabled', 'align', 'alt', 'center', 'data-*' ] | ||||||
|             'img': [ 'src' ], |  | ||||||
|             'section': [ 'class', 'data-note-id' ], |  | ||||||
|             'figure': [ 'class' ], |  | ||||||
|             'span': [ 'class', 'style' ], |  | ||||||
|             'label': [ 'class' ], |  | ||||||
|             'input': [ 'class', 'type', 'disabled' ], |  | ||||||
|             'code': [ 'class' ], |  | ||||||
|             'ul': [ 'class' ], |  | ||||||
|             'table': [ 'class' ], |  | ||||||
|             'en-media': [ 'hash' ] |  | ||||||
|         }, |         }, | ||||||
|         allowedSchemes: [ |         allowedSchemes: [ | ||||||
|             'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'irc', 'gemini', 'git', |             'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'irc', 'gemini', 'git', | ||||||
|  | |||||||
| @ -121,7 +121,11 @@ function importMarkdown(taskContext, file, parentNote) { | |||||||
|     const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); |     const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); | ||||||
| 
 | 
 | ||||||
|     const markdownContent = file.buffer.toString("utf-8"); |     const markdownContent = file.buffer.toString("utf-8"); | ||||||
|     const htmlContent = markdownService.renderToHtml(markdownContent, title); |     let htmlContent = markdownService.renderToHtml(markdownContent, title); | ||||||
|  | 
 | ||||||
|  |     if (taskContext.data.safeImport) { | ||||||
|  |         htmlContent = htmlSanitizer.sanitize(htmlContent); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     const {note} = noteService.createNewNote({ |     const {note} = noteService.createNewNote({ | ||||||
|         parentNoteId: parentNote.noteId, |         parentNoteId: parentNote.noteId, | ||||||
| @ -141,7 +145,10 @@ function importHtml(taskContext, file, parentNote) { | |||||||
|     const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); |     const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); | ||||||
|     let content = file.buffer.toString("utf-8"); |     let content = file.buffer.toString("utf-8"); | ||||||
| 
 | 
 | ||||||
|     content = htmlSanitizer.sanitize(content); |     if (taskContext.data.safeImport) { | ||||||
|  |         content = htmlSanitizer.sanitize(content); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     content = importUtils.handleH1(content, title); |     content = importUtils.handleH1(content, title); | ||||||
| 
 | 
 | ||||||
|     const {note} = noteService.createNewNote({ |     const {note} = noteService.createNewNote({ | ||||||
|  | |||||||
| @ -321,7 +321,9 @@ async function importZip(taskContext, fileBuffer, importRootNote) { | |||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         content = htmlSanitizer.sanitize(content); |         if (taskContext.data.safeImport) { | ||||||
|  |             content = htmlSanitizer.sanitize(content); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         content = content.replace(/<html.*<body[^>]*>/gis, ""); |         content = content.replace(/<html.*<body[^>]*>/gis, ""); | ||||||
|         content = content.replace(/<\/body>.*<\/html>/gis, ""); |         content = content.replace(/<\/body>.*<\/html>/gis, ""); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam