Summary
Notesnook's Web Clipper previously preserved attacker-controlled attributes from clipped pages and rendered them into an unsandboxed, same-origin iframe using contentDocument.write(...), leading to stored cross-site scripting (XSS).
When a crafted clip was opened, event-handler attributes executed JavaScript in the Notesnook origin; in the Electron-based desktop client, this script execution could be escalated to full remote code execution due to nodeIntegration: true and contextIsolation: false.
Affected context
The vulnerability occurs in Notesnook's Web Clipper feature and subsequent note rendering flow.
It is relevant when:
- Users clip content from arbitrary or untrusted web pages.
- The clipped HTML, including root element attributes, is stored and later rendered.
- Notes are displayed in a same-origin iframe without sandboxing or robust HTML sanitization.
In Electron-based desktop builds where Node.js APIs are exposed to web content, successful script execution can be escalated to remote code execution on the user's machine.
Exploit preconditions
- Attack surface: Notesnook Web Clipper and note rendering UI (web, desktop, mobile).
- Required attacker capability: Ability to cause a user to clip a malicious web page, or control content on a page that the victim clips (e.g., compromised site, malicious link, injected widget).
- Stored aspect: Malicious attributes on the source page's root element are preserved into the stored "web-clip" HTML.
- Trigger point: The victim later opens the stored clip in Notesnook; the app renders the HTML into a same-origin, unsandboxed iframe via
contentDocument.write(...). - Why exploitation is possible:
- Attacker-controlled event-handler attributes (
onload,onclick,onmouseover, etc.) are not stripped or sanitized. - The iframe shares origin with the Notesnook app and is not sandboxed, allowing arbitrary script execution in the app context.
- In the desktop Electron app,
nodeIntegration: trueandcontextIsolation: falseexpose Node.js APIs directly to attacker-controlled scripts, enabling RCE.
Why this happens
The core issue is a stored cross-site scripting vulnerability stemming from unsafe handling of HTML captured by the Web Clipper.
The clipper preserves attributes from the source page's root DOM element and embeds them into stored "web-clip" HTML without removing dangerous event-handler attributes or script-capable constructs. Later, when the clip is opened, Notesnook injects this HTML into an iframe via contentDocument.write(...) in a same-origin, unsandboxed context.
This behavior aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting) because attacker-controlled HTML and attributes are rendered as-is in the application origin. In the Electron desktop environment, this XSS chain escalates toward CWE-94: Improper Control of Generation of Code ('Code Injection'), because untrusted script gains access to Node.js APIs due to permissive nodeIntegration and lack of contextIsolation. The abstract insecure pattern is:
- Treating captured HTML as trusted content.
- Rendering it dynamically in a privileged, same-origin context without sanitization or sandboxing.
Potential impact
- Execution of arbitrary JavaScript in the Notesnook web origin when a malicious clip is viewed.
- Theft of sensitive note content, metadata, or authentication/session tokens accessible to the Notesnook web context.
- Account takeover or cross-account data access if session or API credentials can be exfiltrated.
- In the desktop Electron app:
- Execution of arbitrary OS-level commands via Node.js APIs.
- File system access, including reading and modifying local notes, configuration files, or other accessible data.
- Installation of additional malware or establishing persistence on the affected system.
- Use of the compromised desktop as a foothold for further lateral movement in the user's environment.
General mitigation guidance
Effective mitigation generally requires a combination of safer content handling, sandboxing, and least-privilege runtime configuration:
- HTML sanitization for clips:
- Treat all web-clipped HTML as untrusted.
- Normalize and sanitize stored clip content before saving or rendering, removing event-handler attributes, JavaScript URLs, inline scripts, and other active content.
- Prefer a whitelist-based sanitizer that only allows a minimal subset of tags and attributes required for display.
- Safe rendering patterns:
- Avoid using
contentDocument.write(...)with untrusted or semi-trusted HTML. - Render clips in sandboxed iframes with restrictive
sandboxattributes (e.g., disabling script execution and same-origin access) where feasible. - When rich HTML is not strictly necessary, consider rendering a preprocessed, inert representation (e.g., server-side rendered markdown or text-only excerpts).
- Desktop/Electron hardening:
- Configure Electron windows with
nodeIntegration: falseandcontextIsolation: trueby default, especially for any surface that renders user- or network-sourced HTML. - Expose only narrowly scoped, vetted APIs through secure bridges instead of giving direct access to the Node.js runtime.
- Apply the principle of least privilege to the renderer process to minimize the impact of any XSS that might still occur.
- Trust minimization and UX:
- Make it clear in UX and documentation that content clipped from the web is treated as untrusted.
- Consider adding optional "safe view" modes where clipped content is flattened or stripped of interactivity by default.
How teams detect issues like this
The vulnerability can be surfaced using a mix of static inspection, dynamic testing, and configuration review:
- Static analysis and code review:
- Search for uses of
contentDocument.write,document.write, or equivalent sink APIs where input can originate from stored or user-controllable HTML. - Flag flows where data from browser extensions, web clippers, or synchronized cloud storage is rendered without passing through a sanitizer.
- Review iframe creation to ensure
sandboxattributes and restrictive origins are enforced. - In Electron code, audit window construction options for risky flags such as
nodeIntegration: true,contextIsolation: false, and broadpreloadscripts.
- Automated security scanning:
- Use web security scanners or browser automation to create and then render notes containing benign
<img>or root-level elements with event handlers to check for execution. - Incorporate custom rules into linters or SAST tools to flag direct rendering of untrusted HTML into same-origin frames.
- Policy and build-time checks:
- Enforce project-wide policies forbidding unsanitized HTML rendering and requiring sandboxing for any semi-trusted content areas.
- Integrate checks into CI/CD pipelines that fail builds when unsafe Electron configuration patterns or dangerous sink APIs are introduced.
- Runtime monitoring (where possible):
- Instrument logging around clip rendering paths to detect unusual script errors or behavior that might indicate malicious content execution.

