forge_ops_tracker 0.20.0 → 0.21.0

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: d0c84fc309e7191793314f8b54488442383610eefe41df5f793cbfeb660bd9d5
4
- data.tar.gz: e0cb23777cadde88f2c47180d86beede097d904f592e344b20703c4cc1a19541
3
+ metadata.gz: c51ad9b51fd30d2f2524c60fabb955dbd2840a756138a4cf4b9cda47dbd56b49
4
+ data.tar.gz: 8a4b895fa3ba817ea0d352cfaaedfd5dc083e4abf69fb25020a523b890ded319
5
5
  SHA512:
6
- metadata.gz: d0be76c8e1855c31d3949e7c8ef337bf90a34067c78be75c30498a8b0624083c2df69a61ecae76f793cfe15e30552ca66410dc2a527a6d18768760247621573b
7
- data.tar.gz: 7345a1130c32bc7cc8a261d2c1d0f3940edf3b92f99a8472521211805d6a282a65e445d6b03e12819516b89537c292c8fe9f0800a9117afb944073b3f465044d
6
+ metadata.gz: 22e8833e29f4de32284cb8203d135dff386a50845de5235c52ab3a39a5574448a2e14e4e85cada210f1b2a44f0367193d1d6d96e97764f0cb3650b1d31a600af
7
+ data.tar.gz: 31f1973e9840e5b7396ce7a96fc757288468cb50f65b7ba6de5f8bef6625a7211eb340e0fe6043f644602532a708cfb2d6c2c3453c879c9306e40e2fd7eecfe5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.21.0 (2026-10-23)
4
+
5
+ - PII scrubbing catches card numbers however they're grouped (bare, 4-4-4-4, Amex's 4-6-5, or next to a
6
+ security code) when the digits have a card network's prefix and pass the Luhn check, so long ids stay
7
+ readable; IBANs, compact or in groups of four, by their own check digits; and fields named `iban`,
8
+ `account_number`, `routing_number` or `bank_account`. The rules are in sdks/PII_SCRUBBING.md, the same in
9
+ every SDK.
10
+
3
11
  ## 0.20.0 (2026-10-22)
4
12
 
5
13
  - Strict privacy: the message fingerprint now also replaces email addresses with `<email>` and quoted
@@ -22,6 +22,7 @@ module ForgeOpsTracker
22
22
  secret apisecret clientsecret secretkey
23
23
  token accesstoken refreshtoken apikey apitoken authorization authtoken bearer sessiontoken csrftoken
24
24
  creditcard cardnumber cardnum cvv cvv2 cvc
25
+ iban accountnumber routingnumber bankaccount
25
26
  ssn socialsecuritynumber socialsecurity
26
27
  privatekey
27
28
  ].freeze
@@ -37,6 +38,12 @@ module ForgeOpsTracker
37
38
  "GITHUB TOKEN" => /\bgh[pousr]_[A-Za-z0-9]{20,}\b/
38
39
  }.freeze
39
40
 
41
+ # Card numbers in any other shape, and IBANs: see sdks/PII_SCRUBBING.md, which every SDK follows,
42
+ # and sdks/pii_scrubbing_vectors.json (a copy is in spec/fixtures), which pins the results.
43
+ DIGIT_RUN = /(?<![A-Za-z0-9_])\d(?:[ -]?\d)*(?![A-Za-z0-9_])/
44
+ CARD_PREFIXES = /\A(?:4|5[1-5]|2(?:22[1-9]|2[3-9]\d|[3-6]\d\d|7[01]\d|720)|3[47]|6011|64[4-9]|65|35(?:2[89]|[3-8]\d)|36|30[0-5]|62)/
45
+ IBAN = /(?<![A-Za-z0-9_])[A-Z]{2}[0-9]{2}(?:[A-Z0-9]{11,30}|(?: [A-Z0-9]{4}){2,7}(?: [A-Z0-9]{1,4})?)(?![A-Za-z0-9_])/
46
+
40
47
  def self.scrub(value, key: nil)
41
48
  if sensitive_key?(key) && !value.nil?
42
49
  REDACTED
@@ -63,8 +70,64 @@ module ForgeOpsTracker
63
70
  private_class_method :sensitive_key?
64
71
 
65
72
  def self.scrub_string(string)
66
- PATTERNS.reduce(string) { |scrubbed, (label, pattern)| scrubbed.gsub(pattern, "[#{label} FILTERED]") }
73
+ # IBANs first: a spaced IBAN's middle groups look like a formatted card number.
74
+ scrubbed = string.gsub(IBAN) { |candidate| iban?(candidate) ? "[IBAN FILTERED]" : candidate }
75
+ scrubbed = PATTERNS.reduce(scrubbed) { |text, (label, pattern)| text.gsub(pattern, "[#{label} FILTERED]") }
76
+ scrubbed.gsub(DIGIT_RUN) { |run| scrub_card_numbers_in(run) }
67
77
  end
68
78
  private_class_method :scrub_string
79
+
80
+ # From each group of the run on, the longest stretch of whole groups that is a card number is
81
+ # replaced, so a card followed by its CVV, two cards in a row, and Amex's 4-6-5 are all found.
82
+ def self.scrub_card_numbers_in(run)
83
+ groups = run.split(/([ -])/)
84
+ digits = groups.each_slice(2).map(&:first)
85
+ separators = groups.each_slice(2).map { |pair| pair[1] }
86
+ out = +""
87
+ i = 0
88
+ while i < digits.length
89
+ j = (digits.length - 1).downto(i).find { |last| card_number?(digits[i..last].join) }
90
+ if j
91
+ out << "[CREDIT CARD FILTERED]" << separators[j].to_s
92
+ i = j + 1
93
+ else
94
+ out << digits[i] << separators[i].to_s
95
+ i += 1
96
+ end
97
+ end
98
+ out
99
+ end
100
+ private_class_method :scrub_card_numbers_in
101
+
102
+ def self.card_number?(digits)
103
+ digits.length.between?(13, 19) && digits.match?(CARD_PREFIXES) && luhn?(digits)
104
+ end
105
+ private_class_method :card_number?
106
+
107
+ def self.luhn?(digits)
108
+ sum = digits.reverse.each_char.with_index.sum do |char, index|
109
+ value = char.to_i
110
+ next value if index.even?
111
+
112
+ doubled = value * 2
113
+ doubled > 9 ? doubled - 9 : doubled
114
+ end
115
+ (sum % 10).zero?
116
+ end
117
+ private_class_method :luhn?
118
+
119
+ # The IBAN check, a digit at a time: the first four characters moved to the end, letters as two
120
+ # digits (A is 10), and the remainder by 97 is 1.
121
+ def self.iban?(candidate)
122
+ compact = candidate.delete(" ")
123
+ return false unless compact.length.between?(15, 34)
124
+
125
+ rearranged = compact[4..] + compact[0, 4]
126
+ remainder = rearranged.each_char.reduce(0) do |acc, char|
127
+ (char.match?(/[A-Z]/) ? (char.ord - 55).to_s : char).each_char.reduce(acc) { |r, digit| (r * 10 + digit.to_i) % 97 }
128
+ end
129
+ remainder == 1
130
+ end
131
+ private_class_method :iban?
69
132
  end
70
133
  end
@@ -1,3 +1,3 @@
1
1
  module ForgeOpsTracker
2
- VERSION = "0.20.0"
2
+ VERSION = "0.21.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forge_ops_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ForgeOps