Skip to content

Commit b192d52

Browse files
codenerkratob
authored andcommitted
Fix [CVE-2025-25184]: Possible Log Injection in Rack::CommonLogger
1 parent 1bf82b2 commit b192d52

File tree

9 files changed

+17
-11
lines changed

9 files changed

+17
-11
lines changed

Gemfile.1.8.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: rack
33
specs:
4-
rack (1.4.7.19)
4+
rack (1.4.7.20)
55

66
PATH
77
remote: railslts-version

Gemfile.2.3.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: rack
33
specs:
4-
rack (1.4.7.19)
4+
rack (1.4.7.20)
55

66
PATH
77
remote: railslts-version

Gemfile.2.5.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GIT
88
PATH
99
remote: rack
1010
specs:
11-
rack (1.4.7.19)
11+
rack (1.4.7.20)
1212

1313
PATH
1414
remote: railslts-version

Gemfile.2.7.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: rack
33
specs:
4-
rack (1.4.7.19)
4+
rack (1.4.7.20)
55

66
PATH
77
remote: railslts-version

Gemfile.3.1.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: rack
33
specs:
4-
rack (1.4.7.19)
4+
rack (1.4.7.20)
55

66
PATH
77
remote: railslts-version

Gemfile.3.3.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: rack
33
specs:
4-
rack (1.4.7.19)
4+
rack (1.4.7.20)
55

66
PATH
77
remote: railslts-version

rack/lib/rack/commonlogger.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CommonLogger
2121
# lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
2222
#
2323
# %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
24-
FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
24+
FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f }
2525

2626
def initialize(app, logger=nil)
2727
@app = app
@@ -56,11 +56,12 @@ def log(env, status, header, began_at)
5656
now - began_at ]
5757

5858
if defined?("".ord)
59-
msg.gsub!(/[^[:print:]\n]/) { |c| "\\x%02x" % [c.ord] }
59+
msg.gsub!(/[^[:print:]]/) { |c| sprintf("\\x%02x", c.ord) }
6060
else
61-
msg.gsub!(/[^[:print:]\n]/) { |c| "\\x%02x" % [c[0]] }
61+
msg.gsub!(/[^[:print:]]/) { |c| sprintf("\\x%02x", c[0]) }
6262
end
6363

64+
msg[-1] = "\n"
6465
logger.write(msg)
6566
end
6667

rack/lib/rack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Rack
4-
RELEASE = "1.4.7.19"
4+
RELEASE = "1.4.7.20"
55

66
# Return the Rack release as a dotted string.
77
def self.release

rack/test/spec_commonlogger.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@
5151
res.errors.should =~ /"GET \/ " 200 - /
5252
end
5353

54-
should "escape non printable characters except newline" do
54+
should "escape non printable characters including newline" do
5555
log = StringIO.new
5656
Rack::MockRequest.new(Rack::CommonLogger.new(app_without_lint, log)).request("GET\b\x10", "/hello")
5757

5858
log.string.should.match(/GET\\x08\\x10 \/hello/)
59+
60+
Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/", 'REMOTE_USER' => "foo\nbar", "QUERY_STRING" => "bar\nbaz")
61+
log.string.should.match(/\n\z/)
62+
log.string.should.match(/foo\\x0abar/)
63+
log.string.should.match(/bar\\x0abaz/)
5964
end
6065

6166
def length

0 commit comments

Comments
 (0)