yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] extras/try_gzip_static: do not show backtrace on syscall errors
Date: Sun,  5 Jun 2016 23:30:46 +0000	[thread overview]
Message-ID: <20160605233046.32371-1-e@80x24.org> (raw)

On ENAMETOOLONG and perhaps other system errors which we can do
nothing about, we should not spew a giant backtrace which could
be used as an easy DoS vector.
---
 extras/try_gzip_static.rb           |  2 +-
 test/test_extras_try_gzip_static.rb | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/extras/try_gzip_static.rb b/extras/try_gzip_static.rb
index 0d5d63b..31c1aa1 100644
--- a/extras/try_gzip_static.rb
+++ b/extras/try_gzip_static.rb
@@ -203,7 +203,7 @@ def r(code, exc = nil, env = nil)
       msg = msg.dump if /[[:cntrl:]]/ =~ msg # prevent code injection
       logger.warn("#{env['REQUEST_METHOD']} #{env['PATH_INFO']} " \
                   "#{code} #{msg}")
-      if exc.respond_to?(:backtrace)
+      if exc.respond_to?(:backtrace) && !(SystemCallError === exc)
         exc.backtrace.each { |line| logger.warn(line) }
       end
     end
diff --git a/test/test_extras_try_gzip_static.rb b/test/test_extras_try_gzip_static.rb
index c6c8cef..4d20b5a 100644
--- a/test/test_extras_try_gzip_static.rb
+++ b/test/test_extras_try_gzip_static.rb
@@ -34,6 +34,18 @@ def test_gzip_static
       end
     end
 
+    Net::HTTP.start(host, port) do |http|
+      uri = "/COPYING/foo" + ('-' * 4096)
+      begin
+        res = http.request(Net::HTTP::Get.new(uri))
+      end while res.code.to_i == 414 && uri.chop!
+      res = http.request(Net::HTTP::Get.new("/COPYING/foo"))
+      assert_equal 404, res.code.to_i
+      lines = File.readlines(err.path)
+      File.truncate(err.path, 0)
+      assert_operator lines.size, :<, 3, lines.map! { |s| s[0,64] }.inspect
+    end
+
     begin # setup
       gpl = "#{tmpdir}/COPYING"
       gplgz = "#{tmpdir}/COPYING.gz"

                 reply	other threads:[~2016-06-05 23:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160605233046.32371-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).