// For flags

CVE-2021-29474

Relative Path Traversal Attack on note creation

Severity Score

5.8
*CVSS v3.1

Exploit Likelihood

*EPSS

Affected Versions

*CPE

Public Exploits

1
*Multiple Sources

Exploited in Wild

-
*KEV

Decision

-
*SSVC
Descriptions

HedgeDoc (formerly known as CodiMD) is an open-source collaborative markdown editor. An attacker can read arbitrary `.md` files from the server's filesystem due to an improper input validation, which results in the ability to perform a relative path traversal. To verify if you are affected, you can try to open the following URL: `http://localhost:3000/..%2F..%2FREADME#` (replace `http://localhost:3000` with your instance's base-URL e.g. `https://demo.hedgedoc.org/..%2F..%2FREADME#`). If you see a README page being rendered, you run an affected version. The attack works due the fact that the internal router passes the url-encoded alias to the `noteController.showNote`-function. This function passes the input directly to findNote() utility function, that will pass it on the the parseNoteId()-function, that tries to make sense out of the noteId/alias and check if a note already exists and if so, if a corresponding file on disk was updated. If no note exists the note creation-function is called, which pass this unvalidated alias, with a `.md` appended, into a path.join()-function which is read from the filesystem in the follow up routine and provides the pre-filled content of the new note. This allows an attacker to not only read arbitrary `.md` files from the filesystem, but also observes changes to them. The usefulness of this attack can be considered limited, since mainly markdown files are use the file-ending `.md` and all markdown files contained in the hedgedoc project, like the README, are public anyway. If other protections such as a chroot or container or proper file permissions are in place, this attack's usefulness is rather limited. On a reverse-proxy level one can force a URL-decode, which will prevent this attack because the router will not accept such a path.

HedgeDoc (anteriormente conocida como CodiMD) es un editor colaborativo de código abierto. Un atacante puede leer archivos arbitrarios ".md" del sistema de archivos del servidor debido a una comprobación inapropiada de la entrada, lo que resulta en la habilidad de llevar a cabo un salto de ruta relativo. Para comprobar si está afectado, puede intentar abrir la siguiente URL: "http://localhost:3000/..%2F..%2FREADME#" (sustituya "http://localhost:3000" por la URL base de su instancia, por ejemplo "https://demo.hedgedoc.org/..%2F..%2FREADME#"). Si ve que se muestra una página README, significa que está ejecutando una versión afectada. El ataque funciona debido a que el router interno pasa el alias codificado en url a la función "noteController.showNote". Esta función pasa la entrada directamente a la función de utilidad findNote(), que la pasará a la función parseNoteId(), que intenta dar sentido al noteId/alias y comprobar si ya se presenta una nota y, si es así, si se ha actualizado el archivo correspondiente en el disco. Si no se presenta ninguna nota, se llama a la función de creación de notas, que pasa este alias no comprobado, con un ".md" añadido, a una función path.join() que se lee del sistema de archivos en la rutina de seguimiento y proporciona el contenido precargado de la nueva nota. Esto permite a un atacante no sólo leer archivos ".md" arbitrarios del sistema de archivos, sino también observar los cambios en ellos. La utilidad de este ataque puede considerarse limitada, ya que principalmente los archivos markdown usan la terminación de archivo ".md" y todos los archivos markdown contenidos en el proyecto hedgedoc, como el README, son públicos de todos modos. Si se presentan otras protecciones, como un chroot o un contenedor, o los permisos adecuados para los archivos, la utilidad de este ataque es bastante limitada. A nivel de proxy inverso se puede forzar una decodificación de la URL, lo que evitará este ataque porque el router no aceptará dicha ruta

*Credits: N/A
CVSS Scores
Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Changed
Confidentiality
Low
Integrity
None
Availability
None
Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
None
Availability
None
Attack Vector
Network
Attack Complexity
Low
Authentication
None
Confidentiality
Partial
Integrity
None
Availability
None
* Common Vulnerability Scoring System
SSVC
  • Decision:-
Exploitation
-
Automatable
-
Tech. Impact
-
* Organization's Worst-case Scenario
Timeline
  • 2021-03-30 CVE Reserved
  • 2021-04-26 CVE Published
  • 2024-01-10 EPSS Updated
  • 2024-08-03 CVE Updated
  • 2024-08-03 First Exploit
  • ---------- Exploited in Wild
  • ---------- KEV Due Date
CWE
  • CWE-20: Improper Input Validation
  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
CAPEC
Affected Vendors, Products, and Versions
Vendor Product Version Other Status
Vendor Product Version Other Status <-- --> Vendor Product Version Other Status
Hedgedoc
Search vendor "Hedgedoc"
Hedgedoc
Search vendor "Hedgedoc" for product "Hedgedoc"
< 1.8.0
Search vendor "Hedgedoc" for product "Hedgedoc" and version " < 1.8.0"
-
Affected