From 304e43f3e2f4794b90e664a9a83eda4c0d6ca928 Mon Sep 17 00:00:00 2001 From: Victor Pellan Date: Fri, 27 Sep 2024 14:54:16 +0200 Subject: [PATCH] Delete #body method from Rack request gateway and fixed content-length --- Matrixfile | 2 +- lib/datadog/appsec/contrib/rack/gateway/request.rb | 7 ++----- spec/datadog/appsec/contrib/rack/gateway/request_spec.rb | 6 ------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Matrixfile b/Matrixfile index 7808ba72551..fd758cc1db2 100644 --- a/Matrixfile +++ b/Matrixfile @@ -258,7 +258,7 @@ 'redis-5' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby' }, 'appsec:rack' => { - # 'rack-latest' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby', + 'rack-latest' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby', 'rack-3' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby', 'rack-2' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby', # Non-deprecated form of Regexp.new does not backport to Rack 1.x, see: https://github.com/rack/rack/pull/1998 diff --git a/lib/datadog/appsec/contrib/rack/gateway/request.rb b/lib/datadog/appsec/contrib/rack/gateway/request.rb index 9b587bc620d..488d862ee95 100644 --- a/lib/datadog/appsec/contrib/rack/gateway/request.rb +++ b/lib/datadog/appsec/contrib/rack/gateway/request.rb @@ -45,14 +45,11 @@ def headers end result['content-type'] = request.content_type if request.content_type - result['content-length'] = request.content_length if request.content_length + # Since Rack 3.1, content-length is nil if the body is empty, but we still want to send it to the WAF. + result['content-length'] = request.content_length || '0' result end - def body - request.body.read.tap { request.body.rewind } - end - def url request.url end diff --git a/spec/datadog/appsec/contrib/rack/gateway/request_spec.rb b/spec/datadog/appsec/contrib/rack/gateway/request_spec.rb index 4a013808677..f2188537c45 100644 --- a/spec/datadog/appsec/contrib/rack/gateway/request_spec.rb +++ b/spec/datadog/appsec/contrib/rack/gateway/request_spec.rb @@ -65,12 +65,6 @@ end end - describe '#body' do - it 'returns the body' do - expect(request.body).to eq('') - end - end - describe '#url' do it 'returns the url' do expect(request.url).to eq('http://example.com:8080/?a=foo&a=bar&b=baz')