<commit_before>module Identity
  class CSRF < ::Rack::Csrf
    def initialize(app, opts={})
      opts.merge!(raise: true)
      super(app, opts)
    end

    def call(env)
      super(env)
    rescue InvalidCsrfToken
      req = Rack::Request.new(env)
      Identity.log :invalid_csrf_token,
        actual_token: req.params['_csrf'],
        expected_token: env['rack.session']['csrf.token'],
        id: env["REQUEST_IDS"]
      [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
    end
  end
end<commit_msg>Log referrer on CSRF problem<commit_after>module Identity
  class CSRF < ::Rack::Csrf
    def initialize(app, opts={})
      opts.merge!(raise: true)
      super(app, opts)
    end

    def call(env)
      super(env)
    rescue InvalidCsrfToken
      req = Rack::Request.new(env)
      Identity.log :invalid_csrf_token,
        actual_token: req.params['_csrf'],
        expected_token: env['rack.session']['csrf.token'],
        id: env["REQUEST_IDS"],
        referrer: request.referrer
      [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
    end
  end
end
{'fraction_non_alphanumeric': 0.1518418688230009, 'fraction_numerical': 0.0071877807726864335, 'mean_word_length': 2.8680555555555554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996582', 'n_tokens_mistral': 385, 'n_tokens_neox': 376, 'n_words': 77}