diff options
author | Pratik <pratiknaik@gmail.com> | 2015-10-12 18:14:57 -0500 |
---|---|---|
committer | Pratik <pratiknaik@gmail.com> | 2015-10-12 18:14:57 -0500 |
commit | a6ee365703bbee67db7091e6209be29733d034cd (patch) | |
tree | 3588a8b7846209912eb01c67e72d2c32c39a0f56 /lib/action_cable/connection/base.rb | |
parent | d222f7de572f28fc2fa185e9f21cac6f7e6c84f0 (diff) | |
parent | ecab8314eba8519bd593cbc097ef60ee0c285cf2 (diff) | |
download | rails-a6ee365703bbee67db7091e6209be29733d034cd.tar.gz rails-a6ee365703bbee67db7091e6209be29733d034cd.tar.bz2 rails-a6ee365703bbee67db7091e6209be29733d034cd.zip |
Merge pull request #85 from rails/cross-site-forgery-protection
Add support for cross site forgery protection
Diffstat (limited to 'lib/action_cable/connection/base.rb')
-rw-r--r-- | lib/action_cable/connection/base.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index cd7f76f118..2f2fa1fdec 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -70,7 +70,7 @@ module ActionCable def process logger.info started_request_message - if websocket.possible? + if websocket.possible? && allow_request_origin? websocket.on(:open) { |event| send_async :on_open } websocket.on(:message) { |event| on_message event.data } websocket.on(:close) { |event| send_async :on_close } @@ -172,6 +172,17 @@ module ActionCable end + def allow_request_origin? + return true if server.config.disable_request_forgery_protection + + if Array(server.config.allowed_request_origins).include? env['HTTP_ORIGIN'] + true + else + logger.error("Request origin not allowed: #{env['HTTP_ORIGIN']}") + false + end + end + def respond_to_successful_request websocket.rack_response end |