CVE-2023-39517: Insufficient Information (NVD-CWE-noinfo)
value: Joplin is a free, open source note taking and to-do application. A Cross site scripting (XSS) vulnerability in affected versions allows clicking on an untrusted image link to execute arbitrary shell commands. The HTML sanitizer (`packages/renderer/htmlUtils.ts::sanitizeHtml`) preserves `<map>` `<area>` links. However, unlike `<a>` links, the `target` and `href` attributes are not removed. Additionally, because the note preview pane isn't sandboxed to prevent top navigation, links with `target` set to `_top` can replace the toplevel electron page. Because any toplevel electron page, with Joplin's setup, has access to `require` and can require node libraries, a malicious replacement toplevel page can import `child_process` and execute arbitrary shell commands. This issue has been fixed in commit 7c52c3e9a81a52ef1b42a951f9deb9d378d59b0f which is included in release version 2.12.8. Users are advised to upgrade. There are no known workarounds for this vulnerability.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-06-21T20:15Z
Repository: https://github.com/laurent22/joplin
Language: TypeScript
Files changed: packages/app-cli/tests/md_to_html/sanitize_16.html, packages/renderer/htmlUtils.ts
Commit date: 2023-07-15 11:56:12 +0100
Commit message: Desktop: Security: Disallow map and area tags (#8479)


Diff: diff --git a/packages/app-cli/tests/md_to_html/sanitize_16.html b/packages/app-cli/tests/md_to_html/sanitize_16.html
index e6cc433c1c..050f218a94 100644
--- a/packages/app-cli/tests/md_to_html/sanitize_16.html
+++ b/packages/app-cli/tests/md_to_html/sanitize_16.html
@@ -1 +1 @@
-<map name="test" class="jop-noMdConv"><area coords="0,0,1000,1000" href="#" class="jop-noMdConv"/></map><img usemap="#test" src="https://github.com/Ry0taK.png" class="jop-noMdConv"/>
\ No newline at end of file
+<img usemap="#test" src="https://github.com/Ry0taK.png" class="jop-noMdConv"/>
\ No newline at end of file
diff --git a/packages/renderer/htmlUtils.ts b/packages/renderer/htmlUtils.ts
index b48f9bd4ac..54e819d464 100644
--- a/packages/renderer/htmlUtils.ts
+++ b/packages/renderer/htmlUtils.ts
@@ -201,10 +201,15 @@ class HtmlUtils {
 		const disallowedTags = [
 			'script', 'iframe', 'frameset', 'frame', 'object', 'base',
 			'embed', 'link', 'meta', 'noscript', 'button', 'form',
 			'input', 'select', 'textarea', 'option', 'optgroup',
 			'svg',
+
+			// Disallow map and area tags: <area ...> links are currently not
+			// sanitized as well as <a ...> links, allowing potential sandbox
+			// escape.
+			'map', 'area',
 		];
 
 		const parser = new htmlparser2.Parser({
 
 			onopentag: (name: string, attrs: Record<string, string>) => {
@@ -298,12 +303,19 @@ class HtmlUtils {
 			onclosetag: (name: string) => {
 				const current = currentTag();
 
 				if (current === name.toLowerCase()) tagStack.pop();
 
-				if (disallowedTags.includes(current)) {
-					disallowedTagDepth--;
+				// The Markdown sanitization code can result in calls like this:
+				//     sanitizeHtml('<invlaid>')
+				//     sanitizeHtml('</invalid>')
+				// Thus, we need to be able to remove '</invalid>', even if there is no
+				// corresponding opening tag.
+				if (disallowedTags.includes(current) || disallowedTags.includes(name)) {
+					if (disallowedTagDepth > 0) {
+						disallowedTagDepth--;
+					}
 					return;
 				}
 
 				if (disallowedTagDepth) return;
 

Vulnerable code: <map name="test" class="jop-noMdConv"><area coords="0,0,1000,1000" href="#" class="jop-noMdConv"/></map><img usemap="#test" src="https://github.com/Ry0taK.png" class="jop-noMdConv"/>
				if (disallowedTags.includes(current)) {
					disallowedTagDepth--;
Fixed code: <img usemap="#test" src="https://github.com/Ry0taK.png" class="jop-noMdConv"/>

			// Disallow map and area tags: <area ...> links are currently not
			// sanitized as well as <a ...> links, allowing potential sandbox
			// escape.
			'map', 'area',
				// The Markdown sanitization code can result in calls like this:
				//     sanitizeHtml('<invlaid>')
				//     sanitizeHtml('</invalid>')
				// Thus, we need to be able to remove '</invalid>', even if there is no
				// corresponding opening tag.
				if (disallowedTags.includes(current) || disallowedTags.includes(name)) {
					if (disallowedTagDepth > 0) {
						disallowedTagDepth--;
					}