posthog-ruby 3.34.2 → 3.34.4
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 +4 -4
- data/lib/posthog/emails.rb +3 -3
- data/lib/posthog/mcp/sanitization.rb +66 -37
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19f299cd4a1cfc192bd98c7b5bc1ec1b1fed38bcefbe61fbad73b3b5f1567d54
|
|
4
|
+
data.tar.gz: 20838301fba089aeaed57f14355c795145999ca4036b747ac933b9b57e6a2c9e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ddd2561257e60ca531ff06dc0f2b936179901d85d1859872358af45fa38a4b1f3d51c94811adf09adf08e471fc69f7a088c4eba967e798dd635d11bb8eb4cb0
|
|
7
|
+
data.tar.gz: 1880304e4a536a4eae1e7fd06b2a4a3583833ffd3eb19c2cd2533d527ed33d22814ab86d7216942bbd6ecbcebdfe60b4bf5776801b765d2ee62070dad74d5760
|
data/lib/posthog/emails.rb
CHANGED
|
@@ -71,9 +71,9 @@ module PostHog
|
|
|
71
71
|
# of a bounced email: `hard`, `soft` or `unknown`.
|
|
72
72
|
Status = Struct.new(:id, :status, :created_at, :status_at, :reason, keyword_init: true)
|
|
73
73
|
|
|
74
|
-
SEND_PATH = '/api/
|
|
75
|
-
UPLOADS_PATH = '/api/
|
|
76
|
-
STATUS_PATH = '/api/
|
|
74
|
+
SEND_PATH = '/api/messaging/send/email/'
|
|
75
|
+
UPLOADS_PATH = '/api/messaging/attachments/uploads/'
|
|
76
|
+
STATUS_PATH = '/api/messaging/emails/%<message_id>s/'
|
|
77
77
|
US_APP_HOST = 'https://us.posthog.com'
|
|
78
78
|
EU_APP_HOST = 'https://eu.posthog.com'
|
|
79
79
|
CLOUD_APP_HOSTS = {
|
|
@@ -44,7 +44,7 @@ module PostHog
|
|
|
44
44
|
/x
|
|
45
45
|
US_SSN_PATTERN = /\b\d{3}[ .-]\d{2}[ .-]\d{4}\b/
|
|
46
46
|
CREDIT_CARD_CANDIDATE_PATTERN = %r{\b\d(?:[ ./-]?\d){12,}\b}
|
|
47
|
-
|
|
47
|
+
SEPARATED_DIGIT_GROUP_PATTERN = /(\D*)(\d+)/
|
|
48
48
|
PHONE_NANP_PATTERN = %r{(?<![\w+])(?:\+?1[ ./-]?)?(?:\(\d{3}\)[ ./-]?|\d{3}[ ./-])\d{3}[ ./-]\d{4}(?!\w)}
|
|
49
49
|
PHONE_INTL_PATTERN = %r{(?<!\w)\+\d{1,3}(?:[ ./()-]{0,2}\d){7,13}(?!\w)}
|
|
50
50
|
|
|
@@ -140,32 +140,32 @@ module PostHog
|
|
|
140
140
|
|
|
141
141
|
# Within a card candidate, redact every run of whole separator-delimited
|
|
142
142
|
# digit groups whose joined digits are 13-19 long and pass Luhn.
|
|
143
|
+
#
|
|
144
|
+
# Splits into `[separator, digits]` pairs rather than asking each match
|
|
145
|
+
# for its offset: `MatchData#begin` inside `scan` recounts characters from
|
|
146
|
+
# the start of the string, which made this pass quadratic.
|
|
143
147
|
def redact_card_in_match(text)
|
|
144
|
-
groups =
|
|
145
|
-
text.scan(DIGIT_GROUP_PATTERN) do
|
|
146
|
-
groups << [Regexp.last_match[0], Regexp.last_match.begin(0), Regexp.last_match.end(0)]
|
|
147
|
-
end
|
|
148
|
+
groups = text.scan(SEPARATED_DIGIT_GROUP_PATTERN)
|
|
148
149
|
output = +''
|
|
149
|
-
cursor = 0
|
|
150
150
|
first = 0
|
|
151
151
|
while first < groups.length
|
|
152
152
|
digits = +''
|
|
153
153
|
matched_last = -1
|
|
154
154
|
(first...groups.length).each do |last|
|
|
155
|
-
digits << groups[last][
|
|
155
|
+
digits << groups[last][1]
|
|
156
156
|
break if digits.length > 19
|
|
157
157
|
|
|
158
158
|
matched_last = last if digits.length >= 13 && passes_luhn?(digits)
|
|
159
159
|
end
|
|
160
160
|
if matched_last >= 0
|
|
161
|
-
output <<
|
|
162
|
-
cursor = groups[matched_last][2]
|
|
161
|
+
output << groups[first][0] << REDACTED_VALUE
|
|
163
162
|
first = matched_last + 1
|
|
164
163
|
else
|
|
164
|
+
output << groups[first][0] << groups[first][1]
|
|
165
165
|
first += 1
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
|
-
output
|
|
168
|
+
output
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
# Redact structured personal identifiers (emails, IPs, cards, US SSNs,
|
|
@@ -196,19 +196,63 @@ module PostHog
|
|
|
196
196
|
end
|
|
197
197
|
end
|
|
198
198
|
|
|
199
|
+
# {sanitize_captured_value} within truncation's depth and breadth limits,
|
|
200
|
+
# so the cost follows what is captured rather than what the caller sent.
|
|
201
|
+
# {Truncation.normalize} of the result equals it of a full sanitize.
|
|
202
|
+
def sanitize_limited_value(value, remaining_depth = Truncation::MAX_DEPTH)
|
|
203
|
+
case value
|
|
204
|
+
when Array
|
|
205
|
+
return '[Array]' if remaining_depth <= 0
|
|
206
|
+
|
|
207
|
+
limited = value.first(Truncation::MAX_BREADTH).map { |item| sanitize_limited_value(item, remaining_depth - 1) }
|
|
208
|
+
value.length > Truncation::MAX_BREADTH ? limited << '[MaxProperties ~]' : limited
|
|
209
|
+
when Hash
|
|
210
|
+
return '[Object]' if remaining_depth <= 0
|
|
211
|
+
|
|
212
|
+
limited = value.first(Truncation::MAX_BREADTH).to_h do |key, nested|
|
|
213
|
+
[key.to_s, redact_key?(key) ? REDACTED_VALUE : sanitize_limited_value(nested, remaining_depth - 1)]
|
|
214
|
+
end
|
|
215
|
+
limited['...'] = '[MaxProperties ~]' if value.length > Truncation::MAX_BREADTH
|
|
216
|
+
limited
|
|
217
|
+
else sanitize_captured_value(value)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
199
221
|
# Sanitize an event's response, parameters, intent and error. Returns a
|
|
200
222
|
# new shallow copy; does not mutate the input.
|
|
201
223
|
def sanitize_event(event)
|
|
202
224
|
result = event.dup
|
|
203
225
|
result['response'] = sanitize_response(result['response']) unless result['response'].nil?
|
|
204
|
-
result['parameters'] =
|
|
205
|
-
unless result['user_intent'].nil?
|
|
206
|
-
result['user_intent'] = redact_pii(sanitize_captured_value(result['user_intent']))
|
|
207
|
-
end
|
|
226
|
+
result['parameters'] = sanitize_limited_value(result['parameters']) unless result['parameters'].nil?
|
|
227
|
+
result['user_intent'] = sanitize_intent(result['user_intent']) unless result['user_intent'].nil?
|
|
208
228
|
result['error'] = sanitize_exception_values(result['error']) unless result['error'].nil?
|
|
209
229
|
result
|
|
210
230
|
end
|
|
211
231
|
|
|
232
|
+
# The credential pass is linear and sees the whole intent: a private key
|
|
233
|
+
# block or a long word is judged on its full length. The personal-data
|
|
234
|
+
# passes are not, so they scan a head chosen to give the same kept text.
|
|
235
|
+
def sanitize_intent(intent)
|
|
236
|
+
return sanitize_captured_value(intent) unless intent.is_a?(String)
|
|
237
|
+
|
|
238
|
+
redact_pii_head(sanitize_string(intent), Truncation::MAX_USER_INTENT_LENGTH)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Cutting the text changes at most the last ~1.5K characters a scan
|
|
242
|
+
# returns: a match reaches back at most an email's 345 characters, and a
|
|
243
|
+
# redaction grows a match at most from 3 characters to 10. So a head whose scan returns more
|
|
244
|
+
# than twice `keep` gives the same first `keep` characters as the full
|
|
245
|
+
# text. Otherwise the head grows to 40x `keep`, which no run of
|
|
246
|
+
# redactions can shrink below `keep`: each leaves 10 characters of at
|
|
247
|
+
# most 345.
|
|
248
|
+
def redact_pii_head(text, keep)
|
|
249
|
+
head = text[0, 4 * keep]
|
|
250
|
+
redacted = redact_pii(head)
|
|
251
|
+
return redacted if head.length == text.length || redacted.length > 2 * keep
|
|
252
|
+
|
|
253
|
+
redact_pii(text[0, 40 * keep])
|
|
254
|
+
end
|
|
255
|
+
|
|
212
256
|
def sanitize_exception_values(error)
|
|
213
257
|
return error unless error.is_a?(Hash)
|
|
214
258
|
|
|
@@ -340,32 +384,17 @@ module PostHog
|
|
|
340
384
|
# dropping the SDK-injected arguments (they surface as dedicated properties).
|
|
341
385
|
def build_captured_mcp_parameters(request)
|
|
342
386
|
request = stringify_keys(request)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
captured = {}
|
|
346
|
-
%w[id jsonrpc method].each do |key|
|
|
347
|
-
captured[key] = sanitize_captured_value(request[key]) if request.key?(key)
|
|
348
|
-
end
|
|
349
|
-
captured['params'] = build_captured_params(request['params']) if request.key?('params')
|
|
350
|
-
{ 'request' => captured }
|
|
387
|
+
sanitize_limited_value('request' => request.is_a?(Hash) ? captured_request_fields(request) : request)
|
|
351
388
|
end
|
|
352
389
|
|
|
353
|
-
def
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
params.
|
|
357
|
-
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
def build_captured_arguments(arguments)
|
|
362
|
-
return sanitize_captured_value(arguments) unless arguments.is_a?(Hash)
|
|
363
|
-
|
|
364
|
-
arguments.each_with_object({}) do |(key, value), captured|
|
|
365
|
-
next if INJECTED_ARGUMENT_NAMES.include?(key)
|
|
366
|
-
|
|
367
|
-
captured[key] = sanitize_captured_value(value)
|
|
390
|
+
def captured_request_fields(request)
|
|
391
|
+
captured = request.slice('id', 'jsonrpc', 'method')
|
|
392
|
+
params = request['params']
|
|
393
|
+
if params.is_a?(Hash) && params['arguments'].is_a?(Hash)
|
|
394
|
+
params = params.merge('arguments' => params['arguments'].except(*INJECTED_ARGUMENT_NAMES))
|
|
368
395
|
end
|
|
396
|
+
captured['params'] = params if request.key?('params')
|
|
397
|
+
captured
|
|
369
398
|
end
|
|
370
399
|
|
|
371
400
|
# Last-resort credential detection for bare words.
|
data/lib/posthog/version.rb
CHANGED