logstop 0.2.4 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -6
- data/LICENSE.txt +1 -1
- data/README.md +25 -11
- data/lib/logstop/formatter.rb +16 -2
- data/lib/logstop/version.rb +1 -1
- data/lib/logstop.rb +17 -15
- metadata +9 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 270d72c3e5f7b204ba2cacce902adf8593dc6d5cab26d4470182aa41b14f3b5b
|
4
|
+
data.tar.gz: 8d5608be8b5b507e8cd640ee0303731b0608a25affed828a0ece5e3b13424afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4fc28afee3a1c604bf1af432ef8563bebba765f2e1f47dd44c6d6c0b335b3be28698432b8a1ff57eb707e27f396a841f67efb7adba46cc028d9388421db4eef
|
7
|
+
data.tar.gz: 30b74692def2afe3ab7a48cc4235eafbc79660aa98ad3adf4e73ce7adf0c82873b62f42ffc196610e2f61f3acbf5c0bc03aed3c7bb428fd51744db8e2b6a33db
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,43 @@
|
|
1
|
-
## 0.2.
|
1
|
+
## 0.2.8 (2021-11-30)
|
2
|
+
|
3
|
+
- Added support for disabling default rules
|
4
|
+
|
5
|
+
## 0.2.7 (2021-02-08)
|
6
|
+
|
7
|
+
- Fixed filtering for URL-encoded emails with `+`
|
8
|
+
|
9
|
+
## 0.2.6 (2020-04-10)
|
10
|
+
|
11
|
+
- Reduced allocations
|
12
|
+
|
13
|
+
## 0.2.5 (2019-10-27)
|
14
|
+
|
15
|
+
- Fixed filtering UUIDs
|
16
|
+
|
17
|
+
## 0.2.4 (2018-12-11)
|
2
18
|
|
3
19
|
- Added `scubber` option for custom rules
|
4
20
|
- Scrub URL-encoded data
|
5
21
|
|
6
|
-
## 0.2.3
|
22
|
+
## 0.2.3 (2018-05-16)
|
7
23
|
|
8
24
|
- Fixed tagged logging
|
9
25
|
|
10
|
-
## 0.2.2
|
26
|
+
## 0.2.2 (2018-05-15)
|
11
27
|
|
12
28
|
- Added `guard` method
|
13
29
|
|
14
|
-
## 0.2.1
|
30
|
+
## 0.2.1 (2018-05-15)
|
15
31
|
|
16
32
|
- Fix for log broadcaster in Rails console
|
17
33
|
- Fix for URL password filtering
|
18
34
|
|
19
|
-
## 0.2.0
|
35
|
+
## 0.2.0 (2018-04-03)
|
20
36
|
|
21
37
|
- Less aggressive filtering on numbers
|
22
38
|
- Filter passwords in URLs
|
23
39
|
- Added `Logstop.scrub` method
|
24
40
|
|
25
|
-
## 0.1.0
|
41
|
+
## 0.1.0 (2018-03-31)
|
26
42
|
|
27
43
|
- First release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -15,15 +15,15 @@ By default, scrubs:
|
|
15
15
|
- Social Security numbers (SSNs)
|
16
16
|
- passwords in URLs
|
17
17
|
|
18
|
-
Works with all types of logging - Ruby,
|
18
|
+
Works with all types of logging - Ruby, Active Record, Active Job, and more
|
19
19
|
|
20
20
|
```
|
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
|
24
|
+
Works even when sensitive data is URL-encoded with plus encoding
|
25
25
|
|
26
|
-
[![Build Status](https://
|
26
|
+
[![Build Status](https://github.com/ankane/logstop/workflows/build/badge.svg?branch=master)](https://github.com/ankane/logstop/actions)
|
27
27
|
|
28
28
|
## Installation
|
29
29
|
|
@@ -49,13 +49,13 @@ Logstop.guard(Rails.logger)
|
|
49
49
|
|
50
50
|
## Options
|
51
51
|
|
52
|
-
To scrub IP addresses, use:
|
52
|
+
To scrub IP addresses (IPv4), use:
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
Logstop.guard(logger, ip: true)
|
56
56
|
```
|
57
57
|
|
58
|
-
Add custom rules with:
|
58
|
+
Add custom rules with:
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
scrubber = lambda do |msg|
|
@@ -65,6 +65,18 @@ end
|
|
65
65
|
Logstop.guard(logger, scrubber: scrubber)
|
66
66
|
```
|
67
67
|
|
68
|
+
Disable default rules with:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Logstop.guard(logger,
|
72
|
+
email: false,
|
73
|
+
phone: false,
|
74
|
+
credit_card: false,
|
75
|
+
ssn: false,
|
76
|
+
url_password: false
|
77
|
+
)
|
78
|
+
```
|
79
|
+
|
68
80
|
To scrub outside of logging, use:
|
69
81
|
|
70
82
|
```ruby
|
@@ -75,13 +87,15 @@ It supports the same options as `guard`.
|
|
75
87
|
|
76
88
|
## Notes
|
77
89
|
|
78
|
-
This should be used in addition to `config.
|
90
|
+
This should be used in addition to `config.filter_parameters`, not as a replacement.
|
79
91
|
|
80
|
-
|
92
|
+
Learn more about [securing sensitive data in Rails](https://ankane.org/sensitive-data-rails).
|
81
93
|
|
82
|
-
|
94
|
+
Also:
|
83
95
|
|
84
|
-
|
96
|
+
- To scrub existing log files, check out [scrubadub](https://github.com/datascopeanalytics/scrubadub)
|
97
|
+
- To anonymize IP addresses, check out [IP Anonymizer](https://github.com/ankane/ip_anonymizer)
|
98
|
+
- To scan for unencrypted personal data in your database, check out [pdscan](https://github.com/ankane/pdscan)
|
85
99
|
|
86
100
|
## Resources
|
87
101
|
|
@@ -100,11 +114,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
100
114
|
- Write, clarify, or fix documentation
|
101
115
|
- Suggest or add new features
|
102
116
|
|
103
|
-
To get started with development
|
117
|
+
To get started with development:
|
104
118
|
|
105
119
|
```sh
|
106
120
|
git clone https://github.com/ankane/logstop.git
|
107
121
|
cd logstop
|
108
122
|
bundle install
|
109
|
-
rake test
|
123
|
+
bundle exec rake test
|
110
124
|
```
|
data/lib/logstop/formatter.rb
CHANGED
@@ -2,14 +2,28 @@ require "logger"
|
|
2
2
|
|
3
3
|
module Logstop
|
4
4
|
class Formatter < ::Logger::Formatter
|
5
|
-
def initialize(formatter = nil, ip: false, scrubber: nil)
|
5
|
+
def initialize(formatter = nil, url_password: true, email: true, credit_card: true, phone: true, ssn: true, ip: false, scrubber: nil)
|
6
6
|
@formatter = formatter || ::Logger::Formatter.new
|
7
|
+
@url_password = url_password
|
8
|
+
@email = email
|
9
|
+
@credit_card = credit_card
|
10
|
+
@phone = phone
|
11
|
+
@ssn = ssn
|
7
12
|
@ip = ip
|
8
13
|
@scrubber = scrubber
|
9
14
|
end
|
10
15
|
|
11
16
|
def call(severity, timestamp, progname, msg)
|
12
|
-
Logstop.scrub(
|
17
|
+
Logstop.scrub(
|
18
|
+
@formatter.call(severity, timestamp, progname, msg),
|
19
|
+
url_password: @url_password,
|
20
|
+
email: @email,
|
21
|
+
credit_card: @credit_card,
|
22
|
+
phone: @phone,
|
23
|
+
ssn: @ssn,
|
24
|
+
ip: @ip,
|
25
|
+
scrubber: @scrubber
|
26
|
+
)
|
13
27
|
end
|
14
28
|
|
15
29
|
# for tagged logging
|
data/lib/logstop/version.rb
CHANGED
data/lib/logstop.rb
CHANGED
@@ -4,27 +4,29 @@ require "logstop/version"
|
|
4
4
|
|
5
5
|
module Logstop
|
6
6
|
FILTERED_STR = "[FILTERED]".freeze
|
7
|
-
FILTERED_URL_STR = "\\1[FILTERED]
|
7
|
+
FILTERED_URL_STR = "\\1[FILTERED]\\2".freeze
|
8
8
|
|
9
|
-
CREDIT_CARD_REGEX = /\b
|
10
|
-
|
9
|
+
CREDIT_CARD_REGEX = /\b[3456]\d{15}\b/
|
10
|
+
CREDIT_CARD_REGEX_DELIMITERS = /\b[3456]\d{3}[\s+-]\d{4}[\s+-]\d{4}[\s+-]\d{4}\b/
|
11
|
+
EMAIL_REGEX = /\b[\w]([\w+.-]|%2B)+(?:@|%40)[a-z\d-]+(?:\.[a-z\d-]+)*\.[a-z]+\b/i
|
11
12
|
IP_REGEX = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
|
12
|
-
PHONE_REGEX = /\b(
|
13
|
+
PHONE_REGEX = /\b(?:\+\d{1,2}\s)?\(?\d{3}\)?[\s+.-]\d{3}[\s+.-]\d{4}\b/
|
13
14
|
SSN_REGEX = /\b\d{3}[\s+-]\d{2}[\s+-]\d{4}\b/
|
14
|
-
URL_PASSWORD_REGEX = /((
|
15
|
+
URL_PASSWORD_REGEX = /((?:\/\/|%2F%2F)\S+(?::|%3A))\S+(@|%40)/
|
15
16
|
|
16
|
-
def self.scrub(msg, ip: false, scrubber: nil)
|
17
|
-
msg = msg.to_s
|
17
|
+
def self.scrub(msg, url_password: true, email: true, credit_card: true, phone: true, ssn: true, ip: false, scrubber: nil)
|
18
|
+
msg = msg.to_s.dup
|
18
19
|
|
19
20
|
# order filters are applied is important
|
20
|
-
msg
|
21
|
-
|
22
|
-
|
23
|
-
.gsub(CREDIT_CARD_REGEX, FILTERED_STR)
|
24
|
-
.gsub(
|
25
|
-
|
26
|
-
|
27
|
-
msg
|
21
|
+
msg.gsub!(URL_PASSWORD_REGEX, FILTERED_URL_STR) if url_password
|
22
|
+
msg.gsub!(EMAIL_REGEX, FILTERED_STR) if email
|
23
|
+
if credit_card
|
24
|
+
msg.gsub!(CREDIT_CARD_REGEX, FILTERED_STR)
|
25
|
+
msg.gsub!(CREDIT_CARD_REGEX_DELIMITERS, FILTERED_STR)
|
26
|
+
end
|
27
|
+
msg.gsub!(PHONE_REGEX, FILTERED_STR) if phone
|
28
|
+
msg.gsub!(SSN_REGEX, FILTERED_STR) if ssn
|
29
|
+
msg.gsub!(IP_REGEX, FILTERED_STR) if ip
|
28
30
|
|
29
31
|
msg = scrubber.call(msg) if scrubber
|
30
32
|
|
metadata
CHANGED
@@ -1,101 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
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: benchmark-ips
|
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: bundler
|
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: 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'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rake
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
description:
|
98
|
-
email: andrew@chartkick.com
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: andrew@ankane.org
|
99
15
|
executables: []
|
100
16
|
extensions: []
|
101
17
|
extra_rdoc_files: []
|
@@ -111,7 +27,7 @@ homepage: https://github.com/ankane/logstop
|
|
111
27
|
licenses:
|
112
28
|
- MIT
|
113
29
|
metadata: {}
|
114
|
-
post_install_message:
|
30
|
+
post_install_message:
|
115
31
|
rdoc_options: []
|
116
32
|
require_paths:
|
117
33
|
- lib
|
@@ -126,9 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
42
|
- !ruby/object:Gem::Version
|
127
43
|
version: '0'
|
128
44
|
requirements: []
|
129
|
-
|
130
|
-
|
131
|
-
signing_key:
|
45
|
+
rubygems_version: 3.2.32
|
46
|
+
signing_key:
|
132
47
|
specification_version: 4
|
133
48
|
summary: Keep personally identifiable information (PII) out of your logs
|
134
49
|
test_files: []
|