Skip to content

Change default HTML escaping behavior to align with markdown-it #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

diwangs
Copy link

@diwangs diwangs commented Mar 11, 2025

vue-markdown uses markdown-it as its markdown rendering engine. However, it changes the default escaping policy to enable HTML rendering by default, making them more vulnerable to XSS attack. Depending on which application the component library is running under, this vulnerability could lead to severe consequences such as account takeover.

Exploit Example
A simple proof of concept is to have a vue-markdown component that renders a malicious HTML tag from a string state.

<template>
  <div id="app">
    <vue-markdown>{{ content }}</vue-markdown>
  </div>
</template>
<script>
import VueMarkdown from 'vue-markdown'

export default {
  name: 'App',
  components: {
    'vue-markdown': VueMarkdown
  },
  data() {
    return {
      content: "I am a **test**<img src='' onerror='alert(window.origin)'/>"
    }
  }
}
</script>

Alternative Approaches

  • Sanitize user input before calling markdown-it render method using library like dompurify
  • Provide a clear warning in the README that HTML rendering is enabled by default, so that library user could provide their own sanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant