From 00381e7b15c4d2bb48ae346434cb4f1d5ab6ba7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Tue, 14 May 2019 16:23:46 +0300 Subject: [PATCH] fix: disallow ascii control characters in URLs Closes https://github.com/jonschlinkert/remarkable/issues/332 The code here is very similar to other markdown libraries, so I pretty much did what they do: - https://github.com/npm/marky-markdown/blob/008509231558765695938020a376b5b2e4fd4fcc/lib/gfm/override-link-destination-parser.js#L67 - https://github.com/markdown-it/markdown-it/blob/ba6830ba13fb92953a91fb90318964ccd15b82c4/lib/helpers/parse_link_destination.js#L53 --- lib/helpers/parse_link_destination.js | 3 ++- test/fixtures/remarkable/xss.txt | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.js index 14ff19a4..738b91b5 100644 --- a/lib/helpers/parse_link_destination.js +++ b/lib/helpers/parse_link_destination.js @@ -49,7 +49,8 @@ export default function parseLinkDestination(state, pos) { if (code === 0x20) { break; } - if (code > 0x08 && code < 0x0e) { break; } + // ascii control chars + if (code < 0x20 || code === 0x7F) { break; } if (code === 0x5C /* \ */ && pos + 1 < max) { pos += 2; diff --git a/test/fixtures/remarkable/xss.txt b/test/fixtures/remarkable/xss.txt index 6fc22e04..e80a2aca 100644 --- a/test/fixtures/remarkable/xss.txt +++ b/test/fixtures/remarkable/xss.txt @@ -77,3 +77,10 @@ javascript:alert(1)

javascript:alert(1)

javascript:alert(1)

. + + +. +[ASCII control characters XSS](javascript:alert(1)) +. +

[ASCII control characters XSS](javascript:alert(1))

+.