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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 996c1a6196492b32af2c6671404af889a1c42240a4e1e7d7b2047faa25f2ca0b
4
- data.tar.gz: 2874a85dd249f9c9355dc17f7984b5d1fac26977cf98a74a478aafb19849f1b7
3
+ metadata.gz: 25fa65a53db09bbdaf79bc3328b362ba4916a6c053a6509d09c0954bad16630f
4
+ data.tar.gz: 63a35fc75f233f0111c74283aa26e97cfe9e3788d29cb07a896fa87819dd923b
5
5
  SHA512:
6
- metadata.gz: af055d4cb224519ec8a68e5f34f7cac6a7dc91afc0df233fb1fa03890401a04c6af9c1e6b6c118995e3b6b115d337d0e84a60f32037a3b993ae873afc2784c19
7
- data.tar.gz: 55878748c919f917afa735ed3e8c010e8598037ed21786e7ea225d6770ed21aef70fef75efb719b52b8fc42f1eda8619394c8bf5088fe1c951cb12c51c72f58f
6
+ metadata.gz: 124774d6a4f51314d3104712cb8096d4a16cdb1996bda58bd2de38d253ebb0811293e4513b010cb92ca275d13f73471e1ba0542b6f14b7b455fa7119870b399b
7
+ data.tar.gz: da752afaef25ad882edbd5a8ea081c04470d11783ed6e4023498c63dc1308fb59164f79b766e39d690bf92dd7ceb5a2e83426ec22b7d417065cb53fc89a10ef6
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ - Less aggressive filtering on numbers
4
+ - Filter passwords in urls
5
+ - Added `Logstop.scrub` method
6
+
1
7
  ## 0.1.0
2
8
 
3
9
  - First release
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) SELECT "users".* FROM "users" WHERE "users"."email" = ? [["email", "[FILTERED]"]]
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
- class Formatter < ::Logger::Formatter
6
- FILTERED_STR = "[FILTERED]".freeze
5
+ FILTERED_STR = "[FILTERED]".freeze
6
+ FILTERED_URL_STR = "\\1[FILTERED]@".freeze
7
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
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
- def initialize(formatter = nil, ip: false)
15
- @formatter = formatter || ::Logger::Formatter.new
16
- @ip = ip
17
- end
15
+ def self.scrub(msg, ip: false)
16
+ msg = msg.to_s
18
17
 
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
18
+ msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip
22
19
 
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
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
@@ -1,3 +1,3 @@
1
1
  module Logstop
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
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.1.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-31 00:00:00.000000000 Z
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