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

Fix URI encoding in StaticFileHandler#redirect_to #5628

Merged
merged 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/std/http/server/handlers/static_file_handler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,13 @@ describe HTTP::StaticFileHandler do
response.status_code.should eq(400)
end
end

it "handles invalid redirect path" do
response = handle HTTP::Request.new("GET", "test.txt%0A")
response.status_code.should eq(302)
response.headers["Location"].should eq "/test.txt%0A"

response = handle HTTP::Request.new("GET", "/test.txt%0A")
response.status_code.should eq(404)
end
end
2 changes: 1 addition & 1 deletion src/http/server/handlers/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class HTTP::StaticFileHandler
private def redirect_to(context, url)
context.response.status_code = 302

url = URI.escape(url) { |b| URI.unreserved?(b) || b != '/' }
url = URI.escape(url) { |byte| URI.unreserved?(byte) || byte.chr == '/' }
context.response.headers.add "Location", url
end

Expand Down