Skip to content

Improper Neutralization of Script-Related HTML Tags in Notes

High
davidmehren published GHSA-gjg7-4j2h-94fq May 11, 2021

Package

hedgedoc

Affected versions

<1.8.2

Patched versions

1.8.2

Description

Impact

HedgeDoc is vulnerable to an XSS attack using the YAML-metadata of a note. An attacker with write access to a note can embed HTML tags in the Open Graph metadata section of the note, resulting in the frontend rendering the script tag as part of the <head> section.

This vulnerability affects all installations. Unless your instance prevents guests from editing notes, this vulnerability allows unauthenticated attackers to inject JavaScript into notes that allow guest edits. If your instance prevents guests from editing notes, this vulnerability allows authenticated attackers to inject JavaScript into any note pages they have write-access to.

Patches

The simplest patch to this problem is to tell ejs to escape the input from Open Graph definitions.

diff --git a/public/views/hedgedoc/head.ejs b/public/views/hedgedoc/head.ejs
index 44668795..419d5dcc 100644
--- a/public/views/hedgedoc/head.ejs
+++ b/public/views/hedgedoc/head.ejs
@@ -7,7 +7,7 @@
 <%- include('../includes/favicon') %>
 <% for (var og in opengraph) { %>
 <% if (opengraph.hasOwnProperty(og) && opengraph[og].trim() !== '') { %>
-<meta property="og:<%- og %>" content="<%- opengraph[og] %>">
+<meta property="og:<%= og %>" content="<%= opengraph[og] %>">
 <% }} if (!opengraph.hasOwnProperty('image')) { %>
 <meta property="og:image" content="<%- serverURL %>/icons/android-chrome-512x512.png">
 <meta property="og:image:alt" content="HedgeDoc logo">

Workarounds

In order to prevent unauthenticated attacks in can be useful to disable guest edits until the next update. To do this set the following to configuration options:

{
    # other configs
    # …
     "allowAnonymous": false,
     "allowAnonymousEdits": false,

}

Or set the environment variables CMD_ALLOW_ANONYMOUS=false and CMD_ALLOW_ANONYMOUS_EDITS=false.

Credits

This vulnerability was found by Filippo Cremonese.

For more information

If you have any questions or comments about this advisory:

Severity

High
8.1
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N

CVE ID

CVE-2021-29503

Weaknesses

Credits