Skip to content
This repository
Browse code

Sanitize the URLs passed to redirect_to to prevent a potential respon…

…se splitting attack.

CGI.rb and mongrel don't do any sanitization of the contents of HTTP headers, so care needs to be taken.
  • Loading branch information...
commit ba80ff74a9627f676b4c426587ce5ea487665e46 1 parent de0ed53
Michael Koziarski authored October 14, 2008
4  actionpack/lib/action_controller/response.rb
@@ -114,8 +114,8 @@ def etag=(etag)
114 114
 
115 115
     def redirect(url, status)
116 116
       self.status = status
117  
-      self.location = url
118  
-      self.body = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
  117
+      self.location = url.gsub(/[\r\n]/, '')
  118
+      self.body = "<html><body>You are being <a href=\"#{CGI.escapeHTML(url)}\">redirected</a>.</body></html>"
119 119
     end
120 120
 
121 121
     def sending_file?

0 notes on commit ba80ff7

Please sign in to comment.
Something went wrong with that request. Please try again.