logstop 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd3468821cf2db0f736994a67beb26daa32b9bb4ccc8051efac0bbd21b5ff5dc
4
- data.tar.gz: f15cc9e3cf9ff371dc28dccc69201d2e4bfdad9f6e36d0d3d4375a7f505eda75
3
+ metadata.gz: 5ac4acd49c15d9cc5eaaf632ab3550c3b5e148e4b4fd07c5a40375ba39ca86ff
4
+ data.tar.gz: 9e3427aeb3921f9be61fbfb1d9e27f949ff1b9c9d4d023e01696397a34aeb06c
5
5
  SHA512:
6
- metadata.gz: 91dc7ecf3ca0ec7f8b650cff86aafde56ef7102f3fea1b148343e7a1db3802685193f8f7e6cf2f9cb37070d95107f15c908db7b3191b5ca74edd6dfad125ba34
7
- data.tar.gz: 0a4726cece72b09e6023e1605e0d3aaf5296795086bf4d511e0ceb25f380fa2f98b0b8d77cb4f5ff03ff900bb4b0ed2a08a1fbbbad9d4e94bf82809ec9e170c2
6
+ metadata.gz: 5b9c8532cec3764daaaf4fb159db1df4c33961510984336e33f93fc3817fedd02f9082e384857e0c61b29b0f025679eee52b1d2911bca3f0b4e13f2322ffef48
7
+ data.tar.gz: e6e84e9b97efba86d7b2f879522bae3289662e4fe637337b04b95d36d420e69735147185a64c6bfd305fd3368c758148fa0cdc87a06b50f613cbb8f2902f05d1
@@ -1,3 +1,8 @@
1
+ ## 0.2.4 [unreleased]
2
+
3
+ - Added `scubber` option for custom rules
4
+ - Scrub URL-encoded data
5
+
1
6
  ## 0.2.3
2
7
 
3
8
  - Fixed tagged logging
@@ -9,12 +14,12 @@
9
14
  ## 0.2.1
10
15
 
11
16
  - Fix for log broadcaster in Rails console
12
- - Fix for url password filtering
17
+ - Fix for URL password filtering
13
18
 
14
19
  ## 0.2.0
15
20
 
16
21
  - Less aggressive filtering on numbers
17
- - Filter passwords in urls
22
+ - Filter passwords in URLs
18
23
  - Added `Logstop.scrub` method
19
24
 
20
25
  ## 0.1.0
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  :fire: Keep personally identifiable information (PII) out of your logs
4
4
 
5
5
  ```ruby
6
- logger.info "Hi test@test.com!"
6
+ logger.info "Hi test@example.org!"
7
7
  # => Hi [FILTERED]!
8
8
  ```
9
9
 
@@ -13,7 +13,7 @@ By default, scrubs:
13
13
  - phone numbers
14
14
  - credit card numbers
15
15
  - Social Security numbers (SSNs)
16
- - passwords in urls
16
+ - passwords in URLs
17
17
 
18
18
  Works with all types of logging - Ruby, ActiveRecord, ActiveJob, and more
19
19
 
@@ -21,6 +21,8 @@ Works with all types of logging - Ruby, ActiveRecord, ActiveJob, and more
21
21
  User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? [["email", "[FILTERED]"]]
22
22
  ```
23
23
 
24
+ Works even when sensitive data is URL-encoded
25
+
24
26
  [![Build Status](https://travis-ci.org/ankane/logstop.svg?branch=master)](https://travis-ci.org/ankane/logstop)
25
27
 
26
28
  ## Installation
@@ -53,13 +55,25 @@ To scrub IP addresses, use:
53
55
  Logstop.guard(logger, ip: true)
54
56
  ```
55
57
 
58
+ Add custom rules with: [master]
59
+
60
+ ```ruby
61
+ scrubber = lambda do |msg|
62
+ msg.gsub(/custom_regexp/, "[FILTERED]".freeze)
63
+ end
64
+
65
+ Logstop.guard(logger, scrubber: scrubber)
66
+ ```
67
+
56
68
  To scrub outside of logging, use:
57
69
 
58
70
  ```ruby
59
71
  Logstop.scrub(msg)
60
72
  ```
61
73
 
62
- ## Note
74
+ It supports the same options as `guard`.
75
+
76
+ ## Notes
63
77
 
64
78
  This should be used in addition to `config.filtered_parameters`, not as a replacement.
65
79
 
@@ -67,6 +81,8 @@ To scrub existing log files, check out [scrubadub](https://github.com/datascopea
67
81
 
68
82
  To anonymize IP addresses, check out [IP Anonymizer](https://github.com/ankane/ip_anonymizer).
69
83
 
84
+ Learn more about [securing sensitive data in Rails](https://ankane.org/sensitive-data-rails).
85
+
70
86
  ## Resources
71
87
 
72
88
  - [List of PII, as defined by NIST](https://en.wikipedia.org/wiki/Personally_identifiable_information#NIST_definition)
@@ -83,3 +99,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
83
99
  - Fix bugs and [submit pull requests](https://github.com/ankane/logstop/pulls)
84
100
  - Write, clarify, or fix documentation
85
101
  - Suggest or add new features
102
+
103
+ To get started with development and testing:
104
+
105
+ ```sh
106
+ git clone https://github.com/ankane/logstop.git
107
+ cd logstop
108
+ bundle install
109
+ rake test
110
+ ```
@@ -6,25 +6,29 @@ module Logstop
6
6
  FILTERED_STR = "[FILTERED]".freeze
7
7
  FILTERED_URL_STR = "\\1[FILTERED]@".freeze
8
8
 
9
- CREDIT_CARD_REGEX = /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/
10
- EMAIL_REGEX = /\b[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\b/i
9
+ CREDIT_CARD_REGEX = /\b\d{4}[\s+-]?\d{4}[\s+-]?\d{4}[\s+-]?\d{4}\b/
10
+ EMAIL_REGEX = /\b[\w][\w+.-]+(@|%40)[a-z\d-]+(\.[a-z\d-]+)*\.[a-z]+\b/i
11
11
  IP_REGEX = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
12
- PHONE_REGEX = /\b(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}\b/
13
- SSN_REGEX = /\b\d{3}[\s-]\d{2}[\s-]\d{4}\b/
14
- URL_PASSWORD_REGEX = /(\/\/\S+:)\S+@/
12
+ PHONE_REGEX = /\b(\+\d{1,2}\s)?\(?\d{3}\)?[\s+.-]\d{3}[\s+.-]\d{4}\b/
13
+ SSN_REGEX = /\b\d{3}[\s+-]\d{2}[\s+-]\d{4}\b/
14
+ URL_PASSWORD_REGEX = /((\/\/|%2F%2F)\S+(:|%3A))\S+(@|%40)/
15
15
 
16
- def self.scrub(msg, ip: false)
16
+ def self.scrub(msg, ip: false, scrubber: nil)
17
17
  msg = msg.to_s
18
18
 
19
- msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip
20
-
21
19
  # order filters are applied is important
22
- msg
20
+ msg = msg
21
+ .gsub(URL_PASSWORD_REGEX, FILTERED_URL_STR)
22
+ .gsub(EMAIL_REGEX, FILTERED_STR)
23
23
  .gsub(CREDIT_CARD_REGEX, FILTERED_STR)
24
24
  .gsub(PHONE_REGEX, FILTERED_STR)
25
25
  .gsub(SSN_REGEX, FILTERED_STR)
26
- .gsub(URL_PASSWORD_REGEX, FILTERED_URL_STR)
27
- .gsub(EMAIL_REGEX, FILTERED_STR)
26
+
27
+ msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip
28
+
29
+ msg = scrubber.call(msg) if scrubber
30
+
31
+ msg
28
32
  end
29
33
 
30
34
  def self.guard(logger, **options)
@@ -2,13 +2,14 @@ require "logger"
2
2
 
3
3
  module Logstop
4
4
  class Formatter < ::Logger::Formatter
5
- def initialize(formatter = nil, ip: false)
5
+ def initialize(formatter = nil, ip: false, scrubber: nil)
6
6
  @formatter = formatter || ::Logger::Formatter.new
7
7
  @ip = ip
8
+ @scrubber = scrubber
8
9
  end
9
10
 
10
11
  def call(severity, timestamp, progname, msg)
11
- Logstop.scrub(@formatter.call(severity, timestamp, progname, msg), ip: @ip)
12
+ Logstop.scrub(@formatter.call(severity, timestamp, progname, msg), ip: @ip, scrubber: @scrubber)
12
13
  end
13
14
 
14
15
  # for tagged logging
@@ -1,3 +1,3 @@
1
1
  module Logstop
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-16 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: memory_profiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,24 +95,18 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  description:
84
- email:
85
- - andrew@chartkick.com
98
+ email: andrew@chartkick.com
86
99
  executables: []
87
100
  extensions: []
88
101
  extra_rdoc_files: []
89
102
  files:
90
- - ".gitignore"
91
- - ".travis.yml"
92
103
  - CHANGELOG.md
93
- - Gemfile
94
104
  - LICENSE.txt
95
105
  - README.md
96
- - Rakefile
97
106
  - lib/logstop.rb
98
107
  - lib/logstop/formatter.rb
99
108
  - lib/logstop/railtie.rb
100
109
  - lib/logstop/version.rb
101
- - logstop.gemspec
102
110
  homepage: https://github.com/ankane/logstop
103
111
  licenses:
104
112
  - MIT
@@ -111,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
119
  requirements:
112
120
  - - ">="
113
121
  - !ruby/object:Gem::Version
114
- version: '0'
122
+ version: '2.2'
115
123
  required_rubygems_version: !ruby/object:Gem::Requirement
116
124
  requirements:
117
125
  - - ">="
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm: 2.4.2
3
- gemfile:
4
- - Gemfile
5
- sudo: false
6
- before_install: gem install bundler
7
- script: bundle exec rake test
8
- notifications:
9
- email:
10
- on_success: never
11
- on_failure: change
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in logstop.gemspec
6
- gemspec
data/Rakefile DELETED
@@ -1,33 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task default: :test
11
-
12
- task :benchmark do
13
- require "bundler/setup"
14
- Bundler.require
15
- require "benchmark/ips"
16
-
17
- str = StringIO.new
18
- logger = ::Logger.new(str)
19
-
20
- str2 = StringIO.new
21
- logger2 = ::Logger.new(str2)
22
- logger2.formatter = Logstop::Formatter.new
23
-
24
- Benchmark.ips do |x|
25
- x.report "logger" do
26
- logger.info "This is a string: test@test.com"
27
- end
28
-
29
- x.report "logger2" do
30
- logger2.info "This is a string: test@test.com"
31
- end
32
- end
33
- end
@@ -1,28 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "logstop/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "logstop"
8
- spec.version = Logstop::VERSION
9
- spec.authors = ["Andrew Kane"]
10
- spec.email = ["andrew@chartkick.com"]
11
-
12
- spec.summary = "Keep personally identifiable information (PII) out of your logs"
13
- spec.homepage = "https://github.com/ankane/logstop"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
22
-
23
- spec.add_development_dependency "activesupport"
24
- spec.add_development_dependency "benchmark-ips"
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "minitest"
27
- spec.add_development_dependency "rake"
28
- end