Skip to content

Cross-site Scripting in Hackmd.io Notes lead by HTML Injection

High
jackycute published GHSA-22jv-vch8-2vp9 Jul 10, 2024

Package

npm codimd (npm)

Affected versions

2.5.3

Patched versions

2.5.4

Description

Summary

The notebook feature of Hackmd.io permits the rendering of iframe HTML tags with an improperly sanitized name attribute. This vulnerability enables attackers to perform cross-site scripting (XSS) attacks via DOM clobbering.

Details

During the rendering of user-provided HTML tags, the script sanitizer configuration lacks proper setup in terms of whitelisted attributes. Currently, the name attribute is permitted for iframe HTML tags. This inclusion is problematic as the name attributes of certain HTML tags, such as form and iframe, can overshadow the result of document object lookups (e.g., document.script) via DOM clobbering. DOM clobbering is a technique where HTML structure manipulations can alter JavaScript object properties unintentionally. For a comprehensive explanation of DOM clobbering, refer to DOM Clobbering Wiki.

https://github.com/hackmdio/codimd/blob/develop/public/js/render.js#L23
// allow ifram tag with some safe attributes
whiteList.iframe = ['allowfullscreen', 'name', 'referrerpolicy', 'src', 'width', 'height']

PoC

The victim will be alerted with document.cookie by clicking the following url (a shared notes).

The payload:

<iframe name="scripts" src=”https://api.google.com/js/api.js”>alert(document.cookie)</iframe>
<iframe name="scripts" src=”https://api.google.com/js/api.js”>alert(document.cookie)</iframe>

Impact

Any user who opens a shared note containing the malicious payload from an attacker on Hackmd.io is susceptible to the effects of this vulnerability, such as having their cookies stolen.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N

CVE ID

CVE-2024-38354

Weaknesses

Credits