logstop 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/CHANGELOG.md +6 -0
- data/README.md +12 -1
- data/lib/logstop.rb +19 -22
- data/lib/logstop/formatter.rb +14 -0
- data/lib/logstop/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25fa65a53db09bbdaf79bc3328b362ba4916a6c053a6509d09c0954bad16630f
|
4
|
+
data.tar.gz: 63a35fc75f233f0111c74283aa26e97cfe9e3788d29cb07a896fa87819dd923b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 124774d6a4f51314d3104712cb8096d4a16cdb1996bda58bd2de38d253ebb0811293e4513b010cb92ca275d13f73471e1ba0542b6f14b7b455fa7119870b399b
|
7
|
+
data.tar.gz: da752afaef25ad882edbd5a8ea081c04470d11783ed6e4023498c63dc1308fb59164f79b766e39d690bf92dd7ceb5a2e83426ec22b7d417065cb53fc89a10ef6
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,13 +13,16 @@ By default, scrubs:
|
|
13
13
|
- phone numbers
|
14
14
|
- credit card numbers
|
15
15
|
- Social Security numbers (SSNs)
|
16
|
+
- passwords in urls
|
16
17
|
|
17
18
|
Works with all types of logging - Ruby, ActiveRecord, ActiveJob, and more
|
18
19
|
|
19
20
|
```
|
20
|
-
User Load (0.1ms)
|
21
|
+
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? [["email", "[FILTERED]"]]
|
21
22
|
```
|
22
23
|
|
24
|
+
[![Build Status](https://travis-ci.org/ankane/logstop.svg?branch=master)](https://travis-ci.org/ankane/logstop)
|
25
|
+
|
23
26
|
## Installation
|
24
27
|
|
25
28
|
Add this line to your application’s Gemfile:
|
@@ -42,10 +45,18 @@ To scrub IP addresses, use:
|
|
42
45
|
Logstop::Formatter.new(formatter, ip: true)
|
43
46
|
```
|
44
47
|
|
48
|
+
To scrub outside of logging, use:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Logstop.scrub(msg)
|
52
|
+
```
|
53
|
+
|
45
54
|
## Note
|
46
55
|
|
47
56
|
This should be used in addition to `config.filtered_parameters`, not as a replacement.
|
48
57
|
|
58
|
+
To scrub existing log files, check out [scrubadub](https://github.com/datascopeanalytics/scrubadub).
|
59
|
+
|
49
60
|
## Resources
|
50
61
|
|
51
62
|
- [List of PII, as defined by NIST](https://en.wikipedia.org/wiki/Personally_identifiable_information#NIST_definition)
|
data/lib/logstop.rb
CHANGED
@@ -1,31 +1,28 @@
|
|
1
|
+
require "logstop/formatter"
|
1
2
|
require "logstop/version"
|
2
|
-
require "logger"
|
3
3
|
|
4
4
|
module Logstop
|
5
|
-
|
6
|
-
|
5
|
+
FILTERED_STR = "[FILTERED]".freeze
|
6
|
+
FILTERED_URL_STR = "\\1[FILTERED]@".freeze
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
+
URL_PASSWORD_REGEX = /(\/\/\S+:)\S+@/
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
@ip = ip
|
17
|
-
end
|
15
|
+
def self.scrub(msg, ip: false)
|
16
|
+
msg = msg.to_s
|
18
17
|
|
19
|
-
|
20
|
-
output = @formatter.call(severity, timestamp, progname, msg)
|
21
|
-
output = output.gsub(IP_REGEX, FILTERED_STR) if @ip
|
18
|
+
msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
# order filters are applied is important
|
21
|
+
msg
|
22
|
+
.gsub(CREDIT_CARD_REGEX, FILTERED_STR)
|
23
|
+
.gsub(PHONE_REGEX, FILTERED_STR)
|
24
|
+
.gsub(SSN_REGEX, FILTERED_STR)
|
25
|
+
.gsub(EMAIL_REGEX, FILTERED_STR)
|
26
|
+
.gsub(URL_PASSWORD_REGEX, FILTERED_URL_STR)
|
30
27
|
end
|
31
28
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module Logstop
|
4
|
+
class Formatter < ::Logger::Formatter
|
5
|
+
def initialize(formatter = nil, ip: false)
|
6
|
+
@formatter = formatter || ::Logger::Formatter.new
|
7
|
+
@ip = ip
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(severity, timestamp, progname, msg)
|
11
|
+
Logstop.scrub(@formatter.call(severity, timestamp, progname, msg), ip: @ip)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/logstop/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03
|
11
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -74,12 +74,14 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
77
78
|
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
82
83
|
- lib/logstop.rb
|
84
|
+
- lib/logstop/formatter.rb
|
83
85
|
- lib/logstop/version.rb
|
84
86
|
- logstop.gemspec
|
85
87
|
homepage: https://github.com/ankane/logstop
|