Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unescape path on commonlogger #655

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rack/commonlogger.rb
Expand Up @@ -47,7 +47,7 @@ def log(env, status, header, began_at)
env["REMOTE_USER"] || "-",
now.strftime("%d/%b/%Y:%H:%M:%S %z"),
env["REQUEST_METHOD"],
env["PATH_INFO"],
Utils.unescape(env["PATH_INFO"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should catch encoding exceptions here, otherwise this could be abused to prevent evil requests from reaching the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like this :

(Utils.unescape(s = env["PATH_INFO"]) rescue s),

Kind of what we do here:
https://github.com/arthurnn/rack/blob/unescape_logger/lib/rack/request.rb#L311

I dont love the rescue all, but I guess that what we need in here to ensure the behaviour.

env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
env["HTTP_VERSION"],
status.to_s[0..3],
Expand Down
13 changes: 13 additions & 0 deletions test/spec_commonlogger.rb
Expand Up @@ -35,6 +35,19 @@
log.string.should =~ /"GET \/ " 200 #{length} /
end

should "unescape the path" do

app1 = Rack::Lint.new lambda { |env|
env["PATH_INFO"] = ::Rack::Utils.escape(env["PATH_INFO"])
[200,
{"Content-Type" => "text/html", "Content-Length" => length.to_s},
[obj]]}

log = StringIO.new
Rack::MockRequest.new(Rack::CommonLogger.new(app1, log)).get("/favicon.ico")
log.string.should =~ /"GET \/favicon.ico " 200 #{length} /
end

should "work with standartd library logger" do
logdev = StringIO.new
log = Logger.new(logdev)
Expand Down