Skip to content

Commit ba286c0

Browse files
jhawthornooooooo-q
andcommitted
Avoid backtracing in plain_text_for_blockquote_node
[CVE-2024-47888] Co-authored-by: ooooooo_q <[email protected]>
1 parent 27121e8 commit ba286c0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

actiontext/lib/action_text/plain_text_conversion.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ def plain_text_for_figcaption_node(node, index)
6565

6666
def plain_text_for_blockquote_node(node, index)
6767
text = plain_text_for_block(node)
68-
text.sub(/\A(\s*)(.+?)(\s*)\Z/m, '\1“\2”\3')
68+
return "“”" if text.blank?
69+
70+
text = text.dup
71+
text.insert(text.rindex(/\S/) + 1, "”")
72+
text.insert(text.index(/\S/), "“")
73+
text
6974
end
7075

7176
def plain_text_for_li_node(node, index)

actiontext/test/unit/plain_text_conversion_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class ActionText::PlainTextConversionTest < ActiveSupport::TestCase
1717
)
1818
end
1919

20+
test "<blockquote> tag with whitespace" do
21+
assert_converted_to(
22+
" “Hello world!” ",
23+
"<blockquote> Hello world! </blockquote>"
24+
)
25+
end
26+
27+
test "<blockquote> tag with only whitespace" do
28+
assert_converted_to(
29+
"“”",
30+
"<blockquote> </blockquote>"
31+
)
32+
end
33+
2034
test "<ol> tags are separated by two new lines" do
2135
assert_converted_to(
2236
"Hello world!\n\n1. list1\n\n1. list2\n\nHow are you?",

0 commit comments

Comments
 (0)