|
| 1 | +# https://github.com/advisories/GHSA-qcm3-vfq5-wfr2 |
| 2 | +# https://github.com/e23e/CVE-2023-31606#readme |
| 3 | +# https://github.com/jgarber/redcloth/issues/73 |
| 4 | +# https://github.com/jgarber/redcloth/pull/75 |
| 5 | + |
| 6 | +require 'redcloth' |
| 7 | + |
| 8 | +describe 'CVE-2023-31606' do |
| 9 | + |
| 10 | + it 'process malicious html without delay' do |
| 11 | + # INFO (Helio): inside RedCloth repo, running `$ bundle exec rspec .`, with the test below, I can't replicate, |
| 12 | + # on my development machine, the time spent on this sample text. |
| 13 | + # However, on the same development machine, when I run this test this code, in a test-redcloth-regexp.rb script, in a rails app |
| 14 | + # with `gem 'RedCloth'` in it, I was able to get the results indicated in the issue (https://github.com/jgarber/redcloth/issues/73), |
| 15 | + # by https://github.com/e23e |
| 16 | + # Here are the outputs: |
| 17 | + # hac@MBP tcard % time ruby test-redcloth-regexp.rb |
| 18 | + # 0.158047 |
| 19 | + # ruby test-redcloth-regexp.rb 0.12s user 0.11s system 82% cpu 0.279 total |
| 20 | + # hac@MBP tcard % time ruby test-redcloth-regexp.rb |
| 21 | + # 18.457945 |
| 22 | + # ruby test-redcloth-regexp.rb 18.32s user 0.22s system 99% cpu 18.556 total |
| 23 | + # hac@MBP tcard % cat !$ |
| 24 | + # cat test-redcloth-regexp.rb |
| 25 | + # require 'RedCloth' |
| 26 | + # text = '<A' + 'A' * (54773) |
| 27 | + # t1 = Time.now |
| 28 | + # text = RedCloth.new(text, [:sanitize_html]).to_html |
| 29 | + # t2 = Time.now |
| 30 | + # puts (t2-t1) |
| 31 | + # hac@MBP tcard % |
| 32 | + |
| 33 | + text = '<A' + 'A' * (54773) |
| 34 | + |
| 35 | + t1 = Time.now |
| 36 | + res = RedCloth.new(text, [:sanitize_html]).to_html |
| 37 | + t2 = Time.now |
| 38 | + |
| 39 | + expect(t2-t1).to be <= 3 |
| 40 | + end |
| 41 | + |
| 42 | + it 'should keep the generated HTML the same' do |
| 43 | + text = "<a href=https://example.com> Example </a>" |
| 44 | + result = RedCloth.new(text, [:sanitize_html]).to_html |
| 45 | + |
| 46 | + expect(result).to eq("<p><a href=\"https://example.com\"> Example </a></p>") |
| 47 | + end |
| 48 | + |
| 49 | +end |
0 commit comments