=========================================================================Stored XSS through WebSocket treatment writes in Nightscout =========================================================================
Product: Nightscout Web Monitor (aka. cgm-remote-monitor) Repository: https://github.com/nightscout/cgm-remote-monitor Vulnerability: CWE-79 (Improper Neutralization of Input During Web Page Generation) Affected: >= 0.8.1, < 15.0.8 Fixed: 15.0.8 Severity: Critical GHSA: GHSA-5mrq-gpqw-q5v5 CVE: Awaiting assignment CVSS v4.0: AV:N/AC:L/AT:N/PR:L/UI:P/VC:H/VI:H/VA:N/SC:H/SI:H/SA:N
1. Product Description ---------------------- Nightscout is an open-source web application for displaying and sharing continuous glucose monitoring (CGM) data. It can integrate data from CGMs, insulin pumps, automated insulin delivery systems, and related diabetes-management software. Nightscout installations may contain sensitive health and medical-device information, including glucose measurements, insulin delivery information, treatment records, insulin-pump status, and telemetry generated by automated insulin delivery systems. The project is maintained at: https://github.com/nightscout/cgm-remote-monitor 2. Summary ---------- Nightscout contains a stored cross-site scripting vulnerability in the handling and display of treatment records written through its main Socket.IO connection. An authenticated client with permission to create or modify treatments can store unsanitised HTML in treatment fields such as 'notes' or 'enteredBy'. When another user hovers over the affected treatment in the Nightscout dashboard, the treatment tooltip inserts these fields into the page as HTML. Attacker-controlled JavaScript can consequently execute in the Nightscout origin with the permissions and authenticated context of the user viewing the malicious treatment. 3. Details ---------- Nightscout exposes treatment write operations through its main Socket.IO connection. A client with the required treatment permissions can use the 'dbAdd' event to create a treatment containing attacker-controlled values. The minimum relevant permission scopes for the demonstrated attack are: api:treatments:create api:treatments:delete api:treatments:update Nightscout's REST treatment creation path sanitizes submitted objects before storing them. The corresponding WebSocket treatment write path, however, writes treatment objects without passing them through the same purification process. The affected WebSocket handling is located in: 'lib/server/websocket.js' The stored treatment is later displayed by client-side rendering code in: 'lib/client/renderer.js' Treatment tooltip rendering inserts fields including 'notes' and 'enteredBy' into the document using '.html()'. As a result, HTML stored through the WebSocket write path is interpreted as markup rather than displayed as text. The combination of an unsanitized WebSocket write path and an HTML rendering sink therefore creates a persistent cross-site scripting condition. 4. Impact --------- An authenticated attacker with treatment write permissions can create a treatment containing malicious HTML or JavaScript. The payload is stored by Nightscout and subsequently delivered to other users viewing the affected treatment. When a user triggers the treatment tooltip, attacker-controlled JavaScript executes within that user's Nightscout origin. The injected script executes in the authenticated browser context of the victim rather than with only the attacker's original treatment permissions. As a result, the script can interact with Nightscout using the permissions available to the victim. If the victim has elevated or administrative permissions, this may allow the attacker-controlled script to perform privileged Nightscout operations available to that user, including modification of treatment data or other administrative actions exposed to the authenticated client. The vulnerability therefore permits privilege escalation from a client with treatment write access to actions available through the session of a more highly privileged user who views the malicious treatment. 5. Proof of Concept ------------------- The following proof of concept uses an existing authenticated Nightscout browser session. The client must have the treatment permissions required to create the malicious treatment. (() => { const c = window.Nightscout?.client; if (!c?.socket?.connected) { throw new Error("Nightscout connection unavailable."); } c.socket.emit("authorize", { client: "web", secret: c.authorized?.token ? null : c.hashauth.hash(), token: c.authorized?.token }, console.log); const marker = `NS-XSS-POC-${Date.now()}`; const payload = `<img src="data:image/gif;base64,` + `R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" ` + `onload="document.title='${marker}'">`; c.socket.emit("dbAdd", { collection: "treatments", data: { eventType: "Note", created_at: new Date(Date.now() - 300000).toISOString(), duration: 10, enteredBy: "PoC", notes: payload } }, (res) => { const id = res?.[0]?._id; if (!id) return console.error("Failed:", res); localStorage.setItem("nsXssPocId", id); console.log("Created PoC:", { id, marker }); location.reload(); }); })(); The proof of concept stores an image element whose 'onload' handler changes the document title. This provides a visible demonstration of JavaScript execution without performing privileged Nightscout actions. After the treatment has been stored and the page reloaded, hovering over the malicious treatment causes the payload to execute. 6. Affected Versions -------------------- Nightscout versions >= 0.8.1 and < 15.0.8 are affected. The vulnerable behaviour results from the combination of the WebSocket treatment write path accepting unsanitized treatment fields and the client-side treatment tooltip rendering those fields as HTML. Nightscout 15.0.8 contains the fix. 7. Remediation -------------- Users should update to Nightscout 15.0.8 or later, which contains the fix for this vulnerability. The fix prevents treatment data written through the affected WebSocket path from reaching an executable HTML rendering context without appropriate sanitization. Users should upgrade even where treatment write access is restricted, as exploitation requires only treatment write permissions and the stored payload may subsequently execute in the browser of a more privileged Nightscout user. 8. Workaround ------------- Upgrading to Nightscout 15.0.8 or later is the recommended remediation. If an affected installation cannot be upgraded immediately, operators should restrict treatment write permissions to trusted users and clients until the upgrade can be completed. This reduces exposure but does not correct the underlying discrepancy between the WebSocket treatment write path and treatment rendering, and should not be treated as a substitute for upgrading. 9. CVSS ------- Severity: Critical CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:P/VC:H/VI:H/VA:N/SC:H/SI:H/SA:N Attack vector: Network Attack complexity: Low Attack requirements: None Privileges required: Low User interaction: Passive Vulnerable system: High confidentiality and integrity impact; no availability impact. Subsequent system: High confidentiality and integrity impact; no availability impact. 10. References ------------- Research report: https://www.scstudios.tech/research/GHSA-5mrq-gpqw-q5v5 Nightscout: https://github.com/nightscout/cgm-remote-monitor GitHub Security Advisory: https://github.com/nightscout/cgm-remote-monitor/security/advisories/ GHSA-5mrq-gpqw-q5v5 CWE-79: https://cwe.mitre.org/data/definitions/79.html Fix: https://github.com/nightscout/cgm-remote-monitor/pull/8591 Fixed release: https://github.com/nightscout/cgm-remote-monitor/releases/tag/v15.0.8 10. Timeline ------------ 2026-09-01 Vulnerability privately reported to a Nightscout maintainer, with a proof of concept and a demonstration video. 2026-09-02 Private GitHub security report GHSA-5mrq-gpqw-q5v5 submitted. A temporary private fork was created for the report. 2026-09-02 Fix merged in PR #8591 (20:20 UTC, 3 September in Hobart). 2026-09-04 Nightscout 15.0.8 released containing the fix (18:27 UTC, 5 September in Hobart). 2026-09-06 Reporter requested that the advisory be accepted as a draft and reported submitting a CVE request to MITRE. 2026-09-17 Reporter notified the maintainer of an intention to publish a technical disclosure that week and invited objections. 2026-09-19 Maintainer accepted the GitHub security report. 2026-09-22 Reporter joined the Nightscout security team and requested a CVE through GitHub. 2026-09-26 CVE request repeated through GitHub. Further requests were made during October; no CVE ID had been assigned at the time of preparing this disclosure. 2026-10-30 Reporter followed up with the maintainer about publication of the disclosure, noting that the fix was in 15.0.8. 2026-11-13 Maintainer acknowledged the proposed coordinated publication of the disclosure and GHSA. 2026-11-16 Public disclosure and publication. -- Ruben Sutton Software Developer & Security Researcher SuperCode Studios https://www.scstudios.tech/ PGP: FE673 AD759 DC01A 264DC 933FD 4B425 66BB8 B28FA
OpenPGP_0xD4B42566BB8B28FA.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Sent through the Full Disclosure mailing list https://nmap.org/mailman/listinfo/fulldisclosure Web Archives & RSS: https://seclists.org/fulldisclosure/
