/

CVE-2026-42214

Severity:

HIGH RISK

(7.8)

Code Injection in NotepadNext

CVE-2026-42214

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution on User System

Severity:

HIGH RISK

(7.8)

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

NotepadNext versions prior to 0.14 contain a code injection flaw where a file's extension is interpolated directly into a Lua script used for language detection.

If an attacker convinces a user to open a specially named file, embedded Lua code in the file extension can execute with access to powerful Lua standard libraries, potentially leading to arbitrary command execution on the victim's system.

Affected context

This vulnerability appears when NotepadNext uses Lua scripts to detect a file's language based on its extension, and the extension value is inserted into a Lua chunk without sanitization.

It affects environments where:

  • NotepadNext is installed at a version prior to 0.14
  • The detectLanguageFromExtension() logic runs automatically on file open
  • Users may open files obtained from untrusted or semi-trusted sources (e.g., downloaded, emailed, or shared)

The attack hinges on the application treating the file name, specifically the extension portion, as trusted script content.

Exploit preconditions

  • Attack surface: Local GUI application usage (opening files with NotepadNext).
  • Required access: Ability to supply or influence a file name that a victim will open (e.g., by sharing a file, download link, or archive).
  • User interaction: The victim must open the maliciously named file in NotepadNext; no additional prompts or configuration are required.
  • Trigger point: Automatic invocation of detectLanguageFromExtension(), which interpolates the file's extension into a Lua script and executes it.
  • Why exploitation is possible: The file extension is treated as code rather than data, and is inserted into a Lua script without validation or escaping, while luaL_openlibs() exposes powerful standard libraries that allow OS-level command execution.

Why this happens

The underlying issue is a classic code injection pattern, mapped to CWE-94: Improper Control of Generation of Code ('Code Injection').

NotepadNext constructs Lua code at runtime for language detection and directly embeds the file extension into that script.

Because the extension is derived from attacker-controlled input (the file name) and is not sanitized or treated as data, an attacker can craft an extension containing Lua syntax, which is then executed by the embedded interpreter.

The unconditional use of luaL_openlibs() further expands the impact by exposing the os, io, and package libraries, making it trivial for injected Lua code to interact with the underlying operating system.

Potential impact

  • Arbitrary Lua code execution when a victim opens a maliciously named file.
  • Execution of operating system commands with the privileges of the user running NotepadNext.
  • Access to local files via Lua's io library, potentially leading to data theft or manipulation.
  • Installation or execution of additional malware or backdoors on the victim's machine.
  • Abuse of the application as an execution vector in phishing or social engineering campaigns.

General mitigation guidance

From a secure design perspective, mitigation focuses on treating file metadata as untrusted input and eliminating runtime code generation based on it.

Recommended patterns include:

  • Avoid dynamic code generation: Replace string-constructed Lua code for language detection with static tables, mappings, or data-driven lookups that do not require eval-like behavior.
  • Strictly separate data from code: If scripting is necessary, pass untrusted values as data (e.g., variables, parameters) rather than concatenating them into code strings.
  • Input validation and encoding: Apply robust validation or encoding to any user-controlled text that might reach a scripting engine, ensuring characters significant to the language syntax are neutralized.
  • Minimize interpreter capabilities: Restrict or sandbox embedded scripting environments so they do not expose powerful standard libraries (os, io, package) unless strictly required.
  • Principle of least privilege: Run the application with minimal OS privileges so that even if code execution occurs, its ability to affect the system is constrained.

How teams detect issues like this

Detection typically involves identifying insecure use of embedded interpreters and dynamic code generation patterns in desktop applications:

  • Static analysis:
  • Flag string concatenation or interpolation used to build Lua (or other scripting) code from file names, paths, or other user-controlled values.
  • Identify unconditional calls to luaL_openlibs() or equivalent that expose broad capabilities to scripts.
  • Code review signals:
  • Look for helper functions like detectLanguageFromExtension() that accept external input and feed it into a scripting engine.
  • Review any use of eval-like constructs or load() with dynamically assembled strings.
  • Policy and tooling:
  • Establish secure coding guidelines that prohibit runtime code generation from untrusted data.
  • Use automated code review tools configured with rules specific to embedded interpreters (Lua, JavaScript, Python, etc.) to surface risky patterns during CI.

Sources

SourceLink
github.comgithub.com/dail8859/NotepadNext/commit/f3ca1b10aca52f05fd7f4f5ebf9b566d6cd95ccc
github.comgithub.com/dail8859/NotepadNext/releases/tag/v0.14
github.comgithub.com/dail8859/NotepadNext/security/advisories/GHSA-m5fq-c9x5-w54g

Frequently asked

questions

It is not remotely exploitable in a traditional network sense, but an attacker can deliver a maliciously named file via email, downloads, or shared storage. Exploitation occurs locally when the victim opens that file in NotepadNext.

The attacker only needs the ability to supply or influence a file name that a victim will open with NotepadNext. They do not need local account access to the victim's machine.

Replace any dynamic code construction based on file names or other user-controlled data with static, data-driven mappings. If scripting must be used, pass untrusted values as data (parameters) and ensure the interpreter runs in a restricted environment with minimal libraries exposed.

Adopt secure coding practices for embedded interpreters: treat all external input as untrusted, forbid eval-like patterns, apply validation and encoding before data reaches any scripting engine, and enforce these rules with code review and automated analysis in the development pipeline.

Find out what's already
exploitable in your codebase.