/

CVE-2026-43940

Severity:

HIGH RISK

(8.4)

Path Traversal and Untrusted File Loading in Electerm

CVE-2026-43940

Analyzed

Vulnerability type

Category:

Path Traversal and Untrusted File Loading

CWE:

CWE-22, CWE-829

Impact:

Local Code Execution / Full User Compromise

Severity:

HIGH RISK

(8.4)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Electerm's runWidget function constructs file paths by directly concatenating user-controlled widget identifiers and exposes this behavior to the renderer process via IPC without validation.

If an attacker can execute JavaScript in the renderer (for example through a malicious plugin or webview XSS), they can use path traversal to load and execute arbitrary JavaScript files from the victim's filesystem with the full privileges of the Electerm process.

Affected context

This vulnerability affects Electerm instances where:

  • The desktop application exposes the runWidget function from src/app/widgets/load-widget.js to the renderer via asynchronous IPC.
  • Widget identifiers provided by the renderer are used to build filesystem paths with direct string concatenation.
  • The renderer context can be influenced, extended, or scripted (e.g., through plugins, embedded webviews, or other dynamic content).

In such deployments, any JavaScript execution obtained in the renderer can pivot into privileged local code execution via the vulnerable IPC handler.

Exploit preconditions

  • Attack surface: Electerm's renderer process, including:
  • Malicious or compromised plugins
  • Untrusted content rendered in built-in webviews
  • Any XSS or DOM injection vectors within the renderer
  • Required access: Ability to run arbitrary JavaScript in the renderer context (no direct OS-level access required).
  • Trigger point: Invocation of the exposed runWidget IPC endpoint with a crafted widget identifier that includes path traversal sequences (e.g., ../).
  • Why exploitation is possible:
  • runWidget builds paths from user-supplied identifiers using naive string concatenation.
  • There is no sanitization, canonicalization, or restriction to a trusted base directory.
  • The resulting path is used to load and execute JavaScript files, implicitly trusting any file reachable via traversal.

Why this happens

The core issue is a path traversal vulnerability combined with unsafe dynamic script loading:

  • The backend side of the Electron-style application exposes runWidget to the renderer via IPC and treats incoming widget identifiers as trusted.
  • It concatenates these identifiers directly into filesystem paths without normalization or validation against a whitelist or fixed base directory.
  • It then loads and executes the targeted JavaScript file, assuming it is a legitimate widget.

This maps to:

  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attackers can traverse outside the intended widget directory using sequences such as ../.
  • CWE-829: Inclusion of Functionality from Untrusted Control Sphere, because the application allows the renderer to dictate which local file to load and run as code, effectively turning arbitrary files on disk into executable code within the Electerm process.

Potential impact

  • Execution of arbitrary JavaScript from the local filesystem with the privileges of the Electerm process.
  • Full compromise of the user account under which Electerm is running (reading/modifying files, accessing SSH keys, and other sensitive data).
  • Hijacking or tampering with SSH/SFTP/RDP/VNC sessions handled by Electerm.
  • Installation of persistent malware or backdoors through the compromised environment.
  • Lateral movement by abusing stored credentials and remote session capabilities.

General mitigation guidance

Effective mitigation focuses on strict path handling, reducing trust in renderer-supplied identifiers, and hardening code-loading behavior:

  • Constrain file loading to a fixed, canonical directory:
  • Resolve requested paths to an absolute, canonical form and verify they remain within a predefined widget directory before loading.
  • Reject any path that attempts traversal outside this directory.
  • Treat renderer input as untrusted:
  • Apply explicit input validation on widget identifiers (e.g., allow only whitelisted names or IDs).
  • Prefer mapping identifiers to known widget metadata instead of accepting raw paths.
  • Avoid arbitrary dynamic code loading:
  • Replace file-based dynamic require/import logic with a statically defined registry of allowed widgets.
  • If dynamic loading is unavoidable, introduce a manifest that explicitly enumerates permitted files.
  • Apply least-privilege and sandboxing:
  • Restrict the Electerm process's filesystem permissions to the minimum required.
  • Use Electron/Electerm configuration patterns that limit the renderer's capabilities and IPC surface.
  • Harden the IPC boundary:
  • Treat all IPC calls as external inputs; validate, sanitize, and enforce strict schemas on data from the renderer.

How teams detect issues like this

Detection can combine code-level analysis with runtime monitoring:

  • Static analysis and code inspection:
  • Search for IPC handlers that accept renderer input and directly concatenate it into filesystem paths or module loaders.
  • Flag patterns where ../ or user-controlled path segments can influence require, import, fs.readFile, or similar APIs.
  • Identify any use of dynamic require/eval-like constructs sourced from IPC payloads.
  • Security-focused code review:
  • Review Electron/Electerm IPC boundaries to ensure they do not expose sensitive file operations or dynamic code loading.
  • Examine all widget loading mechanisms and verify paths are validated and constrained.
  • Automated tooling:
  • Use SAST tools configured with rules for CWE-22 and CWE-829 to highlight unsafe path construction and untrusted file inclusion.
  • Integrate these checks into CI to prevent reintroduction of similar patterns.
  • Runtime monitoring (where feasible):
  • Log IPC invocations to runWidget and similar handlers, especially when paths include suspicious traversal sequences.
  • Monitor for unexpected reads or code loads from outside known widget directories.

Sources

SourceLink
github.comgithub.com/electerm/electerm/releases/tag/v3.7.16
github.comgithub.com/electerm/electerm/security/advisories/GHSA-f77v-9vpc-6pjm

Frequently asked

questions

Exploitability depends on obtaining JavaScript execution in the renderer process. If an attacker can control a plugin, inject content into a webview, or exploit an XSS in the renderer, they can typically pivot to local code execution in the main process via this flaw.

No direct local OS-level access is required. The key requirement is the ability to run JavaScript in the Electerm renderer, which can often be achieved remotely through application-level bugs or malicious content, after which the attacker can execute arbitrary code locally.

The most robust fix is to eliminate user-controlled paths for code loading: map logical widget identifiers to a static registry or manifest of allowed modules, enforce canonical path checks within a restricted directory, and refuse any request that falls outside this controlled set.

Treat the renderer as untrusted, rigorously validate all IPC inputs, avoid dynamic loading of code based on renderer-supplied values, constrain filesystem access to known-safe directories, and incorporate automated checks for path traversal and untrusted file inclusion into your development and review processes.

Find out what's already
exploitable in your codebase.