Skip to content

Commit

Permalink
Add error handling for invalid redirect path in StaticFileHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jan 22, 2018
1 parent ff02d2d commit 0c2b028
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 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,9 @@ 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(400)
end
end
5 changes: 4 additions & 1 deletion src/http/server/handlers/static_file_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class HTTP::StaticFileHandler
context.response.status_code = 302

url = URI.escape(url) { |b| URI.unreserved?(b) || b != '/' }
context.response.headers.add "Location", url
unless context.response.headers.add? "Location", url
# Bad request if location is invalid header value
context.response.status_code = 400
end
end

private def mime_type(path)
Expand Down

0 comments on commit 0c2b028

Please sign in to comment.