diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index 6d77692140..255a27f6b9 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -10,6 +10,7 @@ # $IPR: httpresponse.rb,v 1.45 2003/07/11 11:02:25 gotoyuzo Exp $ require 'time' +require 'uri' require 'webrick/httpversion' require 'webrick/htmlutils' require 'webrick/httputils' @@ -331,8 +332,9 @@ module WEBrick # res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect def set_redirect(status, url) + url = URI(url).to_s @body = "#{url}.\n" - @header['location'] = url.to_s + @header['location'] = url raise status end diff --git a/test/webrick/test_httpresponse.rb b/test/webrick/test_httpresponse.rb index 6263e0a710..75861caf8f 100644 --- a/test/webrick/test_httpresponse.rb +++ b/test/webrick/test_httpresponse.rb @@ -50,6 +50,27 @@ module WEBrick refute_match 'hack', io.string end + def test_set_redirect_response_splitting + url = "malicious\r\nCookie: hack" + assert_raises(URI::InvalidURIError) do + res.set_redirect(WEBrick::HTTPStatus::MultipleChoices, url) + end + end + + def test_set_redirect_html_injection + url = 'http://example.com////?a