Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix redos #27

Merged
merged 1 commit into from
Oct 8, 2022
Merged

fix redos #27

merged 1 commit into from
Oct 8, 2022

Conversation

ooooooo-q
Copy link
Contributor

Fixed ReDoS when receiving crafted response headers.

PoC

require 'benchmark'

def attack_text(length)
  text = 'charset=' + "\t" * length + "a" + "\t" * length + "a"
  /\bcharset=\s*(.+?)\s*(;|$)/.match(text)
end

Benchmark.bm do |x|
  x.report { attack_text(10) }
  x.report { attack_text(100) }
  x.report { attack_text(1000) }
  x.report { attack_text(10000) }
  x.report { attack_text(100000) }
end
❯ bundle exec ruby encoded_body_benchmark.rb
       user     system      total        real
   0.000009   0.000001   0.000010 (  0.000006)
   0.000062   0.000001   0.000063 (  0.000063)
   0.005081   0.000026   0.005107 (  0.005110)
   0.513256   0.001069   0.514325 (  0.514344)
  53.361165   0.264545  53.625710 ( 53.686721)

Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some serious Regex stuff 👏 , thank you for finding and fixing this performance issue 🙏 !

@iMacTia iMacTia merged commit 3fe6c69 into lostisland:main Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants