Forked from mctaylorpants/request_forgery_protection.rb
          
        
    
          Created
          January 5, 2024 12:08 
        
      - 
      
- 
        Save shotgundebugging/e1cc846c2c7bd9b7fff808d97922d2ac to your computer and use it in GitHub Desktop. 
Revisions
- 
        mctaylorpants revised this gist Jul 30, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,12 +10,13 @@ def form_authenticity_token(form_options: {}) # like BREACH. def masked_authenticity_token(session, form_options: {}) # :doc: # ... raw_token = if per_form_csrf_tokens && action && method # ... else real_csrf_token(session) end one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH) encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token) masked_token = one_time_pad + encrypted_csrf_token Base64.strict_encode64(masked_token) 
- 
        mctaylorpants revised this gist Jul 30, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ def form_authenticity_token(form_options: {}) masked_authenticity_token(session, form_options: form_options) end # Creates a masked version of the authenticity token that varies # on each request. The masking is used to mitigate SSL attacks # like BREACH. 
- 
        mctaylorpants created this gist Jul 30, 2017 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # actionpack/lib/action_controller/metal/request_forgery_protection.rb # Sets the token value for the current session. def form_authenticity_token(form_options: {}) masked_authenticity_token(session, form_options: form_options) end # Creates a masked version of the authenticity token that varies # on each request. The masking is used to mitigate SSL attacks # like BREACH. def masked_authenticity_token(session, form_options: {}) # :doc: # ... raw_token = if per_form_csrf_tokens && action && method # ... else real_csrf_token(session) end one_time_pad = SecureRandom.random_bytes(AUTHENTICITY_TOKEN_LENGTH) encrypted_csrf_token = xor_byte_strings(one_time_pad, raw_token) masked_token = one_time_pad + encrypted_csrf_token Base64.strict_encode64(masked_token) end