/usr/lib/ruby/vendor_ruby/action_dispatch/middleware/ssl.rb is in ruby-actionpack 2:4.2.10-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | module ActionDispatch
class SSL
YEAR = 31536000
def self.default_hsts_options
{ :expires => YEAR, :subdomains => false }
end
def initialize(app, options = {})
@app = app
@hsts = options.fetch(:hsts, {})
@hsts = {} if @hsts == true
@hsts = self.class.default_hsts_options.merge(@hsts) if @hsts
@host = options[:host]
@port = options[:port]
end
def call(env)
request = Request.new(env)
if request.ssl?
status, headers, body = @app.call(env)
headers.reverse_merge!(hsts_headers)
flag_cookies_as_secure!(headers)
[status, headers, body]
else
redirect_to_https(request)
end
end
private
def redirect_to_https(request)
host = @host || request.host
port = @port || request.port
location = "https://#{host}"
location << ":#{port}" if port != 80
location << request.fullpath
headers = { 'Content-Type' => 'text/html', 'Location' => location }
[301, headers, []]
end
# http://tools.ietf.org/html/draft-hodges-strict-transport-sec-02
def hsts_headers
if @hsts
value = "max-age=#{@hsts[:expires].to_i}"
value += "; includeSubDomains" if @hsts[:subdomains]
{ 'Strict-Transport-Security' => value }
else
{}
end
end
def flag_cookies_as_secure!(headers)
if cookies = headers['Set-Cookie']
cookies = cookies.split("\n")
headers['Set-Cookie'] = cookies.map { |cookie|
if cookie !~ /;\s*secure\s*(;|$)/i
"#{cookie}; secure"
else
cookie
end
}.join("\n")
end
end
end
end
|