Sha256: 4680fc7360468d70f764d681b11393c68df467c47653abf789efcf4b7094f356

Contents?: true

Size: 598 Bytes

Versions: 43

Compression:

Stored size: 598 Bytes

Contents

module Rollbar
  module Util
    module IPObfuscator
      require 'ipaddr'
      require 'digest'

      def self.obfuscate_ip(ip_string)
        return ip_string unless Rollbar.configuration.user_ip_obfuscator_secret

        secret = Rollbar.configuration.user_ip_obfuscator_secret
        ip_int32 = IPAddr.new(ip_string, Socket::AF_INET).to_i
        secret_int32 = Digest::MD5.hexdigest(secret)[0..7].to_i(16)
        obfuscated_ip_int32 = ip_int32 ^ secret_int32 % (2 << 31)

        IPAddr.new(obfuscated_ip_int32, Socket::AF_INET).to_s
      rescue
        nil
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
rollbar-2.19.2 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.19.1 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.19.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.18.2 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.18.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.17.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.16.4 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.16.3 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.16.2 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.16.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.6 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.5 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.4 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.3 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.2 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.1 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.15.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.14.1 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.14.0 lib/rollbar/util/ip_obfuscator.rb
rollbar-2.13.3 lib/rollbar/util/ip_obfuscator.rb