Hi all, 👋
We often have bots hit our systems with malformed HTTP headers. One of the malformed HTTP headers they apparently try (a lot), is a plain number (e.g. HTTP_2). This causes the following line to throw an "undefined method `tr' for nil:NilClass (NoMethodError)":
|
h[k.gsub(/^HTTP_/, '').downcase!.tr('_', '-')] = v if k =~ /^HTTP_/ |
k =~ /^HTTP_/ is matched, k.gsub(/^HTTP_/, '') results into "2", which becomes nil through downcase!:
[527]dev(main):0> "2".downcase!
=> nil
I'm not exactly sure what the right solution is, given that we're already working with a new object after the gsub, a regular downcase (without !) might work (although that will create another object):
[526]dev(main):0> "2".downcase
=> "2"
To reproduce, spin up a Rails app with dd trace, enable appsec, instrument Rack, and send a request with an integer as HTTP header:
~ curl http://localhost:3001 -H "2: 3"
Puma caught this error: undefined method `tr' for nil:NilClass (NoMethodError)
Hi all, 👋
We often have bots hit our systems with malformed HTTP headers. One of the malformed HTTP headers they apparently try (a lot), is a plain number (e.g.
HTTP_2). This causes the following line to throw an "undefined method `tr' for nil:NilClass (NoMethodError)":dd-trace-rb/lib/datadog/appsec/contrib/rack/gateway/request.rb
Line 44 in f867bd9
k =~ /^HTTP_/is matched,k.gsub(/^HTTP_/, '')results into"2", which becomesnilthroughdowncase!:I'm not exactly sure what the right solution is, given that we're already working with a new object after the
gsub, a regulardowncase(without!) might work (although that will create another object):To reproduce, spin up a Rails app with dd trace, enable appsec, instrument Rack, and send a request with an integer as HTTP header: