logstop 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06f0dd3d6fdaab9b3b43855f0cfca8d282be00b92b7ca0cce0fca78563e15942
4
- data.tar.gz: f6c531bedfc8fff417f150c81ea3c16b0fffcfa2d11a322113f4e46f34061c28
3
+ metadata.gz: 270d72c3e5f7b204ba2cacce902adf8593dc6d5cab26d4470182aa41b14f3b5b
4
+ data.tar.gz: 8d5608be8b5b507e8cd640ee0303731b0608a25affed828a0ece5e3b13424afe
5
5
  SHA512:
6
- metadata.gz: cf0546107ba926046989f0962817ddfcd9f5f1b43ed569bdd50982702388a4c4f76ef41bcb74515973a7b4346e11c49c7727a5468c8bf1baabdadbf259284c5c
7
- data.tar.gz: ff895c82dd97a3c7977fd30ed360185c05e78cf0db601c548cf39733b37a8367a1934870d2144acf40829896da38bc46a747fc9c1957ff3b635be3a5975d8d43
6
+ metadata.gz: c4fc28afee3a1c604bf1af432ef8563bebba765f2e1f47dd44c6d6c0b335b3be28698432b8a1ff57eb707e27f396a841f67efb7adba46cc028d9388421db4eef
7
+ data.tar.gz: 30b74692def2afe3ab7a48cc4235eafbc79660aa98ad3adf4e73ce7adf0c82873b62f42ffc196610e2f61f3acbf5c0bc03aed3c7bb428fd51744db8e2b6a33db
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.8 (2021-11-30)
2
+
3
+ - Added support for disabling default rules
4
+
1
5
  ## 0.2.7 (2021-02-08)
2
6
 
3
7
  - Fixed filtering for URL-encoded emails with `+`
data/README.md CHANGED
@@ -21,7 +21,7 @@ Works with all types of logging - Ruby, Active Record, Active Job, 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
24
+ Works even when sensitive data is URL-encoded with plus encoding
25
25
 
26
26
  [![Build Status](https://github.com/ankane/logstop/workflows/build/badge.svg?branch=master)](https://github.com/ankane/logstop/actions)
27
27
 
@@ -49,7 +49,7 @@ 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)
@@ -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
@@ -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(@formatter.call(severity, timestamp, progname, msg), ip: @ip, scrubber: @scrubber)
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
@@ -1,3 +1,3 @@
1
1
  module Logstop
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
data/lib/logstop.rb CHANGED
@@ -14,17 +14,18 @@ module Logstop
14
14
  SSN_REGEX = /\b\d{3}[\s+-]\d{2}[\s+-]\d{4}\b/
15
15
  URL_PASSWORD_REGEX = /((?:\/\/|%2F%2F)\S+(?::|%3A))\S+(@|%40)/
16
16
 
17
- def self.scrub(msg, ip: false, scrubber: nil)
17
+ def self.scrub(msg, url_password: true, email: true, credit_card: true, phone: true, ssn: true, ip: false, scrubber: nil)
18
18
  msg = msg.to_s.dup
19
19
 
20
20
  # order filters are applied is important
21
- msg.gsub!(URL_PASSWORD_REGEX, FILTERED_URL_STR)
22
- msg.gsub!(EMAIL_REGEX, FILTERED_STR)
23
- msg.gsub!(CREDIT_CARD_REGEX, FILTERED_STR)
24
- msg.gsub!(CREDIT_CARD_REGEX_DELIMITERS, FILTERED_STR)
25
- msg.gsub!(PHONE_REGEX, FILTERED_STR)
26
- msg.gsub!(SSN_REGEX, FILTERED_STR)
27
-
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
28
29
  msg.gsub!(IP_REGEX, FILTERED_STR) if ip
29
30
 
30
31
  msg = scrubber.call(msg) if scrubber
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.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  requirements: []
45
- rubygems_version: 3.2.3
45
+ rubygems_version: 3.2.32
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Keep personally identifiable information (PII) out of your logs