clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: clogger-public@yhbt.net
Subject: [PATCH] escape env['REQUEST_METHOD'] for non-strict HTTP servers
Date: Thu, 16 Jun 2022 16:13:51 +0000	[thread overview]
Message-ID: <20220616161351.29591-1-bofh@yhbt.net> (raw)

This doesn't affect most Rack HTTP servers since they have
strict parsers, but is safer in case one doesn't...

Influenced by CVE-2022-30123.
---
 ext/clogger_ext/clogger.c | 5 +++--
 lib/clogger/pure.rb       | 3 +--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 079817c..2ec9510 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -447,10 +447,11 @@ static void append_request(struct clogger *c)
 {
 	VALUE tmp;
 
-	/* REQUEST_METHOD doesn't need escaping, Rack::Lint governs it */
 	tmp = rb_hash_aref(c->env, g_REQUEST_METHOD);
-	if (!NIL_P(tmp))
+	if (!NIL_P(tmp)) {
+		tmp = byte_xs(tmp);
 		rb_str_buf_append(c->log_buf, tmp);
+	}
 
 	rb_str_buf_append(c->log_buf, g_space);
 
diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb
index 8f1f706..7f82992 100644
--- a/lib/clogger/pure.rb
+++ b/lib/clogger/pure.rb
@@ -118,8 +118,7 @@ private
       version = env['HTTP_VERSION'] and version = " #{byte_xs(version)}"
       qs = env['QUERY_STRING']
       qs.empty? or qs = "?#{byte_xs(qs)}"
-      "#{env['REQUEST_METHOD']} " \
-        "#{request_uri(env)}#{version}"
+      "#{byte_xs(env['REQUEST_METHOD'] || '')} #{request_uri(env)}#{version}"
     when :request_uri
       request_uri(env)
     when :request_length

                 reply	other threads:[~2022-06-16 16:13 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/clogger/

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

  git send-email \
    --in-reply-to=20220616161351.29591-1-bofh@yhbt.net \
    --to=bofh@yhbt.net \
    --cc=clogger-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/clogger.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).