Skip to content

Commit 3896b48

Browse files
committed
merge revision(s) 59897:
lib/webrick/log.rb: sanitize any type of logs It had failed to sanitize some type of exception messages. Reported and patched by Yusuke Endoh (mame) at https://hackerone.com/reports/223363 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ac6f289 commit 3896b48

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Thu Sep 14 20:25:55 2017 Yusuke Endoh <mame@ruby-lang.org>
2+
3+
lib/webrick/log.rb: sanitize any type of logs
4+
5+
It had failed to sanitize some type of exception messages. Reported and
6+
patched by Yusuke Endoh (mame) at https://hackerone.com/reports/223363
7+
18
Thu Sep 14 13:32:39 2017 Nobuyoshi Nakada <nobu@ruby-lang.org>
29

310
parse.y: empty hash in defined

lib/webrick/httpstatus.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ module HTTPStatus
2323
##
2424
# Root of the HTTP status class hierarchy
2525
class Status < StandardError
26-
def initialize(*args) # :nodoc:
27-
args[0] = AccessLog.escape(args[0]) unless args.empty?
28-
super(*args)
29-
end
3026
class << self
3127
attr_reader :code, :reason_phrase # :nodoc:
3228
end

lib/webrick/log.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ def debug?; @level >= DEBUG; end
118118
# * Otherwise it will return +arg+.inspect.
119119
def format(arg)
120120
if arg.is_a?(Exception)
121-
"#{arg.class}: #{arg.message}\n\t" <<
121+
"#{arg.class}: #{AccessLog.escape(arg.message)}\n\t" <<
122122
arg.backtrace.join("\n\t") << "\n"
123123
elsif arg.respond_to?(:to_str)
124-
arg.to_str
124+
AccessLog.escape(arg.to_str)
125125
else
126126
arg.inspect
127127
end

test/webrick/test_httpauth.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ def test_basic_auth3
9898
}
9999
end
100100

101+
def test_bad_username_with_control_characters
102+
log_tester = lambda {|log, access_log|
103+
assert_equal(2, log.length)
104+
assert_match(/ERROR Basic WEBrick's realm: foo\\ebar: the user is not allowed./, log[0])
105+
assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, log[1])
106+
}
107+
TestWEBrick.start_httpserver({}, log_tester) {|server, addr, port, log|
108+
realm = "WEBrick's realm"
109+
path = "/basic_auth"
110+
111+
Tempfile.create("test_webrick_auth") {|tmpfile|
112+
tmpfile.close
113+
tmp_pass = WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path)
114+
tmp_pass.set_passwd(realm, "webrick", "supersecretpassword")
115+
tmp_pass.set_passwd(realm, "foo", "supersecretpassword")
116+
tmp_pass.flush
117+
118+
htpasswd = WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path)
119+
users = []
120+
htpasswd.each{|user, pass| users << user }
121+
server.mount_proc(path){|req, res|
122+
auth = WEBrick::HTTPAuth::BasicAuth.new(
123+
:Realm => realm, :UserDB => htpasswd,
124+
:Logger => server.logger
125+
)
126+
auth.authenticate(req, res)
127+
res.body = "hoge"
128+
}
129+
http = Net::HTTP.new(addr, port)
130+
g = Net::HTTP::Get.new(path)
131+
g.basic_auth("foo\ebar", "passwd")
132+
http.request(g){|res| assert_not_equal("hoge", res.body, log.call) }
133+
}
134+
}
135+
end
136+
101137
DIGESTRES_ = /
102138
([a-zA-Z\-]+)
103139
[ \t]*(?:\r\n[ \t]*)*

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.3.5"
22
#define RUBY_RELEASE_DATE "2017-09-14"
3-
#define RUBY_PATCHLEVEL 375
3+
#define RUBY_PATCHLEVEL 376
44

55
#define RUBY_RELEASE_YEAR 2017
66
#define RUBY_RELEASE_MONTH 9

0 commit comments

Comments
 (0)