Skip to content

Commit

Permalink
Merge pull request #14214 from skateman/websocket-forwarded-for
Browse files Browse the repository at this point in the history
Fetch the allowed WebSocket origin from the XFH header when possible
  • Loading branch information
martinpovolny authored Mar 8, 2017
2 parents cf439c2 + a2b70a9 commit dd2f00d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/websocket_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def not_found
# Primitive same-origin policy checking in production
def same_origin_as_host?(env)
proto = Rack::Request.new(env).ssl? ? 'https' : 'http'
Rails.env.development? || env['HTTP_ORIGIN'] == "#{proto}://#{env['HTTP_HOST']}"
host = env['HTTP_X_FORWARDED_HOST'] ? env['HTTP_X_FORWARDED_HOST'].split(/,\s*/).first : env['HTTP_HOST']
Rails.env.development? || env['HTTP_ORIGIN'] == "#{proto}://#{host}"
end
end

0 comments on commit dd2f00d

Please sign in to comment.