Skip to content

Cross-site Scripting (XSS) via URI #925

Closed

Description

@buglloc

Browsers support both lowercase and uppercase x in hexadecimal form of HTML character entity (tested on Chromium && FF).
But marked unescape only lowercase:

// https://github.com/chjj/marked/blob/master/lib/marked.js#L1096-L1108

function unescape(html) {
	// explicitly match decimal, hex, and named HTML entities 
  return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
    n = n.toLowerCase();
    if (n === 'colon') return ':';
    if (n.charAt(0) === '#') {
      return n.charAt(1) === 'x'
        ? String.fromCharCode(parseInt(n.substring(2), 16))
        : String.fromCharCode(+n.substring(1));
    }
    return '';
  });
}

This allow attacker to create link with javascript code.
For example, this code:

var marked = require('marked');
marked.setOptions({
  renderer: new marked.Renderer(),
  sanitize: true
});

text = `
lower[click me](javascript:...)lower
upper[click me](javascript:...)upper
`;

console.log(marked(text));

Will render:

<p>lowerlower
upper<a href="javascript&#X3a;...">click me</a>upper</p>

Browser example: https://www.buglloc.com/marked.html
Tested on Marked v0.3.6 + Chromium 60.0.3112.90 and Firefox 55.0.1

Activity

  1. matt- commented on Aug 29, 2017

    @matt-
    Contributor

    You are right. this should should be a case-insensitive match:

    html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig

    unfortunately the maintainer is not longer around to push a change to npm. I will push a change to the master branch but unfortunately that may be as far as this change goes.

  2. CSEMike commented on Oct 25, 2017

    @CSEMike

    Hi Matt -- did this issue ever result in a pull request? Thanks!

  3. added
    L1 - broken
    on Dec 1, 2017
  4. joshbruce commented on Dec 1, 2017

    @joshbruce
    Member

    See #937

  5. reopened this on Dec 4, 2017
  6. matt- commented on Dec 4, 2017

    @matt-
    Contributor

    Just tested this and it is still an issue. Why was this closed? what tests were added?

  7. joshbruce commented on Dec 5, 2017

    @joshbruce
    Member

    See #926

  8. added a commit that references this issue on Nov 8, 2021
    3960417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L1 - broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions