Skip to content
Logseq Issues 13596

Logseq Issues 13596

github.com • November 9, 2026

Affected software: Logseq desktop 2.0.1 (released 2026-07-13) and later, including nightly builds and current master (commit ee8bedfb16ceb282bfcca070efee474de7f44a51 , 2026-09-20); GitHub: logseq/logseq. The writeDotdirFile primitive has been exported as an SDK function since 2.0.1; the openExternalLink launch primitive already exists in 0.10.15 (released 2025-12-01)

Affected platforms: Windows / macOS / Linux (Electron desktop application)

Attack prerequisites: the victim's Logseq desktop app is running with a graph open; the API Server has been started inside the app (API icon in the top-right corner → Start, or autostart enabled in the configuration); the API Server token configuration keeps its default state (empty list); the victim's browser loads an attacker-controlled web page once

Severity: Critical — a malicious web page achieves arbitrary command execution on the victim's machine through unauthenticated requests, and the command output is returned to the attacker's page (immediate execution via the file: URL; the same write primitive drops payloads into the Windows Startup folder for persistence at every login)

1. Vulnerability Description

1.1 Attack scenario and impact

The Logseq desktop app embeds a local HTTP API server (Fastify, listening on 127.0.0.1:12315 by default; started by the user from the API icon in the app's top-right corner, or configured to start automatically with the app). Its POST /api endpoint forwards the method name given in the request body to the app's renderer process and invokes any exported plugin-SDK function by name. The server's authentication logic depends on a token list the user configures in advance: when the token list is empty (the default installation state), the authentication function is skipped entirely and a request carrying any forged Authorization value passes authentication — the default configuration holds no valid credentials, the when-let short-circuits on the nil token list, and every token comparison is skipped — leaving every endpoint open to any requester. The server also enables CORS with Access-Control-Allow-Origin: * , so any website can call these endpoints cross-origin from a browser and read the responses.

The victim is running Logseq with the API Server started (tokens kept at the default empty list), then opens an attacker-controlled web page in a browser. JavaScript on that page sends cross-origin requests to and performs, in order:

Arbitrary write to any path : it calls logseq.app.writeDotdirFile(file, content, subRoot) and abuses the directory traversal in the third parameter (sub-root) to write a file with an arbitrary name and arbitrary content (binary content supported) to any path under the victim's directory — for example a .bat script dropped into the Windows Startup folder, achieving persistent arbitrary command execution (Linux/macOS equivalent landing spots: ~/.config/autostart/*.desktop , ~/Library/LaunchAgents/*.plist , ~/.bashrc );

Immediate execution : it calls logseq.app.openExternalLink and abuses the double allow of its substring-style check and the preload-level file: protocol allowlist to make the app's main process call shell.openExternal with a file:///…?ref= URL, launching the just-written script (or any local executable) immediately through the system ShellExecuteEx.

Both requests take effect as soon as they are sent; whether the browser reads the responses has no bearing on the outcome of the command execution. To the victim the entire attack appears as opening an ordinary web page, after which attacker-chosen commands execute on the system. The getCurrentGraph endpoint returns the current graph's local absolute path, locating the directory for assembling absolute landing paths such as %TEMP% and the Startup folder (an information-gathering half-step). The command output can then be read back to the attacker's page through the loadPluginReadme primitive on the same unauthenticated server (its directory argument is fully caller-controlled and it reads readme.md from that directory), yielding full command execution with output retrieval.

1.2 Other capabilities exposed by the same root cause

The same unauthenticated API additionally allows: reading the victim's Logseq account refresh-token / access-token (session credential theft), full-text and export of all private notes, injection of logseq/custom.js scripts into a graph (executed when the app loads the graph), reading the contents of files named package.json / readme.md in any directory, and writing package.json into any directory (overwriting Node project manifests to implant install hooks); the arbitrary command execution chain above is the highest-impact combination among these.

All quoted source is taken from the audit baseline master@ ee8bedfb ; line numbers are the actual line numbers of that revision; the corresponding code in the 2.0.1 release is identical character for character (verified block by block).

2.1 Authentication is skipped entirely under the default configuration (core flaw)

src/electron/electron/server.cljs:83-103 :

The token list is stored in configs.edn in the user data directory ( src/electron/electron/configs.cljs:12, 40-43 ). The file created on the app's first run contains no server/tokens key (that key is written only after the user performs a save in the token management panel), so (get cfg :server/tokens) returns nil. The first binding of validate-auth-token , (string/replace token "Bearer " "") , executes before the when-let : a request omitting the Authorization header makes this string replacement run against undefined and throw a TypeError, so the request is rejected with 401; a request carrying any Authorization value (fully attacker-controlled, e.g. Bearer anonymous ) makes the when-let short-circuit on the nil token list, every token comparison is skipped, and callback() lets the request through — authentication is equivalent to nonexistent, and in the default state every request to /api and /mcp carrying any forged Authorization value reaches the business handlers. Verified live (Windows 11, 2.0.1 installed build): a request omitting the header returns 401 ( Cannot read properties of undefined (reading 'replace') ); requests carrying Authorization: Bearer anonymous and carrying the meaningless value garbage both return 200 with business data.

2.2 CORS is fully open (origin:"*")

src/electron/electron/server.cljs:160-165 :

origin:"*" lets cross-origin requests from any origin (including local file pages with null Origin) pass the preflight and read the responses; @fastify/cors mirrors the request's Access-Control-Request-Headers by default, so preflights carrying the Content-Type: application/json and Authorization headers are also allowed — verified live (Windows 11, 2.0.1 installed build): the preflight response header is access-control-allow-headers: authorization, content-type .

2.3 The /api endpoint forwards method names by name to every exported plugin-SDK function (no method whitelist)

src/electron/electron/server.cljs:73-81 :

After being forwarded over IPC to the renderer process it is handled by src/main/electron/listener.cljs:110-135 :

The namespace field is merely a selector between SDK objects; the method-name part can be any exported function on window.logseq.api ( 170 ^:export functions in src/main/logseq/api.cljs ), including file read/write primitives exported for the plugin host's internal use. Although the main window is configured with nodeIntegration:false and contextIsolation:true ( src/electron/electron/window.cljs:51-60 ), all sensitive operations of these SDK functions execute in the main process over the IPC channels exposed by preload, so the sandbox configuration places no constraint on this call chain.

2.4 Directory traversal in the write_dotdir_file sub-root parameter (arbitrary file write to any path)

src/main/logseq/api/plugin.cljs:57-80 :

src/main/logseq/api/plugin.cljs:104-126 :

The validation function assert-storage-path! only checks whether the file argument stays inside the join result of subRoot , while subRoot itself is joined onto ~/.logseq with no constraint of any kind — passing sub-root = "../AppData/Roaming/Microsoft/Windows/Start /Programs/Startup" resolves the target directory to the Windows Startup folder, with file and content fully attacker-controlled. Binary content is recognized by binary-content? (plugin.cljs:92-102) as a JSON object of the shape {"type":"Buffer","data":[...]} and then goes through window.apis.writeFileBytes (preload.js:144-148, fs.writeFileSync plus recursive directory creation). The write chain applies no path-scope validation at any level:

write_dotdir_file appears as an exported SDK function since 2.0.1 ( src/main/logseq/api.cljs:36 ); in 0.10.15 the same function is private and used only internally by write_user_tmp_file , which pins the sub-root to "tmp" .

2.5 The open_external_link substring check and the preload file: protocol allowlist (local program launch)

src/main/logseq/api/app.cljs:116-119 (application-level check):

resources/js/preload.js:9, 84-90 (preload-level check and execution):

Crafting file:///C:/Windows/System32/notepad.exe?ref= : new URL(...).protocol is file: , which hits the preload allowlist; the https:// in the query string hits the application-level re-find substring check. shell.openExternal ultimately hands the file: URL to ShellExecuteEx on Windows, launching the target executable directly. Verified live (Windows 11, ShellExecuteEx-equivalent command):

Combined with the arbitrary write in 2.4, the attacker drops an arbitrary script/program first and launches it immediately afterwards; command execution completes within seconds of the web page loading. The same primitive also works standalone against executables at any known path on the victim's machine (e.g. programs in the browser's default download directory). Both checks are character-for-character identical in the 0.10.15 release.

3.1 Reproduction steps

Install and start the Logseq desktop app (2.0.1 or later) and open any graph (a newly created DB graph is recommended — the default type for new graphs in 2.x).

Click the API icon in the app's top-right corner, choose Start , and confirm the server status is Running (default address ); open the token management panel and confirm the token list is empty (the default state).

Save the POC in 3.2 as poc-unauth-api-rce.html and serve it over HTTP (simulating the attacker's website):

Open (or the LAN address) in Chrome/Edge. The page is loaded from a real HTTP Origin and every request carries a genuine cross-site Origin header; the target server's CORS is origin:"*" , so opening it via file:// (Origin: null) reaches the server equally well.

The page provides an arbitrary-command input box (default command whoami & hostname ). Clicking Execute makes the page perform three unauthenticated calls automatically: getCurrentGraph returns the current graph's local absolute path and extracts the victim's directory; writeDotdirFile wraps the command from the input box into logseq-rce.bat (with the command output redirected to %TEMP%\logseq-cmd\readme.md and a unique completion marker appended at the end) and writes it into %TEMP% with the subRoot ../AppData/Local/Temp escaping ~/.logseq ; openExternalLink launches the .bat immediately via file:///…?ref= — the command executes on the victim's machine.

The page then polls a fourth unauthenticated call, loadPluginReadme (directory argument fully caller-controlled; it reads readme.md under that directory); once the completion marker is read, the command output is echoed directly into the page's output box — the default command echoes the victim's username and computer name, and command execution and result retrieval are carried out entirely by the attacker's page.

Change the input box to any other command (e.g. ver , tasklist | findstr logseq , start notepad ) and click Execute again: the output is echoed in real time or the program pops up directly — the command content is fully attacker-controlled; the subRoot can likewise be changed to ../Desktop or the Startup folder ../AppData/Roaming/Microsoft/Windows/Start /Programs/Startup (persistence: automatic execution at every login).

3.3 Equivalent command-line requests

Enforce API Server authentication : check server/tokens before the server starts and refuse to start the external endpoints while the list is empty (or auto-generate a high-entropy random token on first start, allowing an anonymous mode only after explicit user confirmation); make validate-auth-token treat "no token configured" as a terminal deny state, eliminating the when-let short-circuit.

Tighten CORS and request-origin validation : remove origin:"*" and replace it with an explicit origin allowlist; add Host / Origin header validation to all routes, blocking cross-origin web pages and DNS-rebinding requests.

Method whitelist for /api : proxy only an explicitly declared subset of remotely callable APIs; move plugin-host-internal high-privilege primitives such as write_dotdir_file , load_plugin_config , save_plugin_package_json , and get_state_from_store out of remote reach.

Fix the sub-root directory traversal : write_rootdir_file / read_rootdir_file / unlink_rootdir_file! should run a single bounds check, rooted at ~/.logseq , against the final fully-joined absolute path, so .. escapes in the subRoot argument are rejected at the entry point.

Fix open_external_link and the preload protocol allowlist : at the application level, strictly validate the scheme of the parsed URL (allow only https: / http: ), replacing the re-find substring match; remove file: from preload's ALLOWED_EXTERNAL_PROTOCOLS (opening local files should go through explicit openPath / showItemInFolder -style APIs with path-context validation in the main process).

Main-process IPC defense in depth : add path-scope constraints to the :writeFile and :readFile handlers (an allowlist of graph/plugin directories), so arbitrary strings on the renderer side can no longer turn directly into file reads and writes at arbitrary paths.

tiensonqin closed this as completed on Nov 9, 2026