logstop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 996c1a6196492b32af2c6671404af889a1c42240a4e1e7d7b2047faa25f2ca0b
4
+ data.tar.gz: 2874a85dd249f9c9355dc17f7984b5d1fac26977cf98a74a478aafb19849f1b7
5
+ SHA512:
6
+ metadata.gz: af055d4cb224519ec8a68e5f34f7cac6a7dc91afc0df233fb1fa03890401a04c6af9c1e6b6c118995e3b6b115d337d0e84a60f32037a3b993ae873afc2784c19
7
+ data.tar.gz: 55878748c919f917afa735ed3e8c010e8598037ed21786e7ea225d6770ed21aef70fef75efb719b52b8fc42f1eda8619394c8bf5088fe1c951cb12c51c72f58f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ - First release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Logstop
2
+
3
+ :fire: Keep personally identifiable information (PII) out of your logs
4
+
5
+ ```ruby
6
+ logger.info "Hi test@test.com!"
7
+ # => Hi [FILTERED]!
8
+ ```
9
+
10
+ By default, scrubs:
11
+
12
+ - email addresses
13
+ - phone numbers
14
+ - credit card numbers
15
+ - Social Security numbers (SSNs)
16
+
17
+ Works with all types of logging - Ruby, ActiveRecord, ActiveJob, and more
18
+
19
+ ```
20
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? [["email", "[FILTERED]"]]
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application’s Gemfile:
26
+
27
+ ```ruby
28
+ gem 'logstop'
29
+ ```
30
+
31
+ And add it to your logger:
32
+
33
+ ```ruby
34
+ logger.formatter = Logstop::Formatter.new(logger.formatter)
35
+ ```
36
+
37
+ ## Options
38
+
39
+ To scrub IP addresses, use:
40
+
41
+ ```ruby
42
+ Logstop::Formatter.new(formatter, ip: true)
43
+ ```
44
+
45
+ ## Note
46
+
47
+ This should be used in addition to `config.filtered_parameters`, not as a replacement.
48
+
49
+ ## Resources
50
+
51
+ - [List of PII, as defined by NIST](https://en.wikipedia.org/wiki/Personally_identifiable_information#NIST_definition)
52
+
53
+ ## History
54
+
55
+ View the [changelog](CHANGELOG.md)
56
+
57
+ ## Contributing
58
+
59
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
60
+
61
+ - [Report bugs](https://github.com/ankane/logstop/issues)
62
+ - Fix bugs and [submit pull requests](https://github.com/ankane/logstop/pulls)
63
+ - Write, clarify, or fix documentation
64
+ - Suggest or add new features
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,31 @@
1
+ require "logstop/version"
2
+ require "logger"
3
+
4
+ module Logstop
5
+ class Formatter < ::Logger::Formatter
6
+ FILTERED_STR = "[FILTERED]".freeze
7
+
8
+ CREDIT_CARD_REGEX = /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/
9
+ EMAIL_REGEX = /\b[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\b/i
10
+ IP_REGEX = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
11
+ PHONE_REGEX = /\b(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\b/i
12
+ SSN_REGEX = /\b\d{3}[\s-]?\d{2}[\s-]?\d{4}\b/i
13
+
14
+ def initialize(formatter = nil, ip: false)
15
+ @formatter = formatter || ::Logger::Formatter.new
16
+ @ip = ip
17
+ end
18
+
19
+ def call(severity, timestamp, progname, msg)
20
+ output = @formatter.call(severity, timestamp, progname, msg)
21
+ output = output.gsub(IP_REGEX, FILTERED_STR) if @ip
22
+
23
+ # order filters are applied is important
24
+ output
25
+ .gsub(CREDIT_CARD_REGEX, FILTERED_STR)
26
+ .gsub(PHONE_REGEX, FILTERED_STR)
27
+ .gsub(SSN_REGEX, FILTERED_STR)
28
+ .gsub(EMAIL_REGEX, FILTERED_STR)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Logstop
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
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 "benchmark-ips"
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark-ips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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'
69
+ description:
70
+ email:
71
+ - andrew@chartkick.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CHANGELOG.md
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/logstop.rb
83
+ - lib/logstop/version.rb
84
+ - logstop.gemspec
85
+ homepage: https://github.com/ankane/logstop
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.7.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Keep personally identifiable information (PII) out of your logs
109
+ test_files: []