Skip to content

Commit a699c82

Browse files
committed
Fix a security issue using :quote with :escape_html
Reported by @johan-smits.
1 parent 6270d6b commit a699c82

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Version 3.5.1 (Security)
4+
5+
* Fix a security vulnerability using `:quote` in combination with the
6+
`:escape_html` option.
7+
8+
Reported by *Johan Smits*.
9+
310
## Version 3.5.0
411

512
* Avoid mutating the options hash passed to a render object.

ext/redcarpet/html.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,15 @@ rndr_quote(struct buf *ob, const struct buf *text, void *opaque)
255255
if (!text || !text->size)
256256
return 0;
257257

258+
struct html_renderopt *options = opaque;
259+
258260
BUFPUTSL(ob, "<q>");
259-
bufput(ob, text->data, text->size);
261+
262+
if (options->flags & HTML_ESCAPE)
263+
escape_html(ob, text->data, text->size);
264+
else
265+
bufput(ob, text->data, text->size);
266+
260267
BUFPUTSL(ob, "</q>");
261268

262269
return 1;

lib/redcarpet.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'redcarpet/compat'
33

44
module Redcarpet
5-
VERSION = '3.5.0'
5+
VERSION = '3.5.1'
66

77
class Markdown
88
attr_reader :renderer

redcarpet.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# encoding: utf-8
22
Gem::Specification.new do |s|
33
s.name = 'redcarpet'
4-
s.version = '3.5.0'
4+
s.version = '3.5.1'
55
s.summary = "Markdown that smells nice"
66
s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
7-
s.date = '2019-07-29'
7+
s.date = '2020-12-15'
88
s.email = '[email protected]'
99
s.homepage = 'http://github.com/vmg/redcarpet'
1010
s.authors = ["Natacha Porté", "Vicent Martí"]

test/markdown_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ def test_quote_flag_works
220220
assert_equal '<p>this is a <q>quote</q></p>', output
221221
end
222222

223+
def test_quote_flag_honors_escape_html
224+
text = 'We are not "<svg/onload=pwned>"'
225+
226+
output_enabled = render(text, with: [:quote, :escape_html])
227+
output_disabled = render(text, with: [:quote])
228+
229+
assert_equal "<p>We are not <q>&lt;svg/onload=pwned&gt;</q></p>", output_enabled
230+
assert_equal "<p>We are not <q><svg/onload=pwned></q></p>", output_disabled
231+
end
232+
223233
def test_that_fenced_flag_works
224234
text = <<-fenced.strip_heredoc
225235
This is a simple test

0 commit comments

Comments
 (0)