SECURITY: enforce hostname to match discourse hostname

This ensures that the hostname rails uses for various helpers always matches
the Discourse hostname
This commit is contained in:
Sam
2018-11-15 15:22:02 +11:00
parent 6fde58ff90
commit e7001f879a
3 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Middleware
class EnforceHostname
def initialize(app, settings = nil)
@app = app
end
def call(env)
# enforces hostname to match the hostname of our connection
# this middleware lives after rails multisite so at this point
# Discourse.current_hostname MUST be canonical, enforce it so
# all Rails helpers are guarenteed to use it unconditionally and
# never generate incorrect links
env[Rack::Request::HTTP_X_FORWARDED_HOST] = nil
env[Rack::HTTP_HOST] = Discourse.current_hostname
@app.call(env)
end
end
end