Summary
A stored cross-site scripting vulnerability in Notesnook's note export flow allows unescaped note fields to be injected into an HTML template and executed when exporting notes to PDF.
When this malicious HTML is rendered in an unsandboxed, same-origin iframe, it enables script execution in the Notesnook origin, which can escalate to remote code execution in the Electron-based desktop app due to permissive WebView settings.
Affected context
This vulnerability occurs in the Notesnook export-to-PDF functionality, where user-controlled note data (such as title, headline, and content) is embedded into an HTML template.
The issue is present when:
- Notes are created or edited with untrusted content that later gets exported;
- The export pipeline inserts these fields into HTML without escaping or sanitization;
- The resulting HTML is rendered inside a same-origin, unsandboxed iframe (via
iframe.srcdoc) in the Web/Desktop and mobile apps.
The most severe impact is seen in the desktop app, where the Electron environment allows Node.js access from rendered web content.
Exploit preconditions
- Attack surface: Notesnook note content and metadata that eventually pass through the export-to-HTML/PDF functionality.
- Required access: Ability to create, edit, or otherwise influence the contents of a note (e.g., via a shared device, compromised user account, or any workflow where untrusted content can land in a note).
- Trigger point: User-initiated note export, particularly export to PDF, which causes the generated HTML to be rendered in a same-origin iframe using
iframe.srcdoc. - Why exploitation is possible:
- Note fields are inserted into the HTML export template without HTML escaping or sanitization.
- The HTML is rendered in an iframe that is not sandboxed and shares the same origin as the main Notesnook application.
- In the desktop app, Electron is configured with
nodeIntegration: trueandcontextIsolation: false, exposing powerful Node.js APIs to injected scripts and enabling RCE.
Why this happens
The root cause is improper output encoding of user-controlled note fields when generating HTML for export.
Instead of treating note titles, headlines, and content as plain text and encoding them before insertion into the HTML template, the application directly interpolates these values into HTML.
This behavior maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), because it allows attacker-controlled data to become active script.
The escalation to remote code execution in the desktop app ties into CWE-94: Improper Control of Generation of Code, as injected JavaScript is given access to Node.js APIs due to permissive Electron configuration, allowing arbitrary code execution on the host machine.
Potential impact
- Stored XSS that executes whenever a malicious note is exported to PDF.
- Theft or manipulation of user data accessible within the Notesnook origin (e.g., reading or modifying notes).
- Account takeover scenarios, such as exfiltrating authentication tokens or session data, where available in the renderer context.
- Arbitrary command execution on the host machine for desktop users, via Node.js APIs exposed by Electron.
- Installation of additional malware or persistence mechanisms on systems running the desktop app.
General mitigation guidance
Effective mitigation focuses on strict output encoding, content isolation, and hardening of the desktop runtime:
- Apply context-appropriate HTML escaping to all user-controlled fields (titles, headlines, content) before inserting them into any HTML template. Treat note content as untrusted text by default.
- Where rich text is required, use a whitelisting HTML sanitizer that strips or neutralizes scripts, event handlers, and dangerous attributes, instead of attempting ad-hoc filtering.
- Render untrusted or semi-trusted HTML in sandboxed iframes (
sandboxattribute) with the minimal set of allowed capabilities, and avoid sharing the same origin if possible. - In the Electron desktop environment, follow secure-by-default settings:
- Disable
nodeIntegrationin renderer processes that display web content. - Enable
contextIsolationand use secure, well-defined IPC channels for privileged operations. - Avoid exposing Node.js or OS-level capabilities directly to web-origin JavaScript.
- Enforce a defense-in-depth approach: treat any data that originated from users or external systems as untrusted at every processing step, not only at input time.
How teams detect issues like this
Organizations and projects can detect similar patterns through a combination of static analysis, review practices, and security testing:
- Static analysis and linters:
- Flag direct interpolation of user-controlled data into HTML strings, templates, or
srcdocwithout encoding. - Detect patterns where
iframe.srcdocis assigned dynamic content without sanitization. - For Electron apps, flag the use of
nodeIntegration: trueandcontextIsolation: falsein production builds. - Code review signals:
- Review all export/preview flows where rich text or HTML is generated from note content or metadata.
- Verify that any HTML templating layer applies consistent, centralized output encoding.
- Inspect uses of
iframeand webviews to ensure sandboxing and strict origins. - Security testing:
- Perform manual and automated XSS testing on note creation, editing, and export functionality by injecting benign test payloads.
- Use dynamic analysis tools that simulate note workflows and attempt payload execution on export and preview steps.
- Policy and CI integration:
- Integrate secure coding guidelines for Electron, including a policy that forbids Node.js access in standard renderer processes.
- Add CI checks that enforce safe Electron configuration and template encoding patterns before merging changes.

