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:
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.
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:
Or set the environment variables
CMD_ALLOW_ANONYMOUS=false
andCMD_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: