monsimas commited on
Commit
24bc975
·
verified ·
1 Parent(s): 9e7dbfc

Sync scrub.py with skill (private-IP pattern)

Browse files
Files changed (1) hide show
  1. scrub.py +17 -0
scrub.py CHANGED
@@ -37,6 +37,17 @@ WIN_PATH = re.compile(r'([A-Za-z]:\\Users\\)([^\\\s"\']+)', re.IGNORECASE)
37
 
38
  EMAIL = re.compile(r'\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b')
39
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Secrets — each tuple is (name, compiled regex). Keep these conservative
41
  # enough to avoid mangling ordinary prose but broad enough to catch real keys.
42
  SECRET_PATTERNS = [
@@ -88,6 +99,12 @@ def redact_string(s, counts):
88
  return "[REDACTED_EMAIL]"
89
  s = EMAIL.sub(_email, s)
90
 
 
 
 
 
 
 
91
  return s
92
 
93
 
 
37
 
38
  EMAIL = re.compile(r'\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b')
39
 
40
+ # RFC1918 private / internal IPv4 addresses. Not a secret, but it leaks internal
41
+ # network topology (DB hosts, service IPs), so it is redacted like home paths —
42
+ # without causing the server backstop to reject the whole donation. The four-octet
43
+ # shape with a fixed private prefix avoids mangling version numbers like 1.2.3.4.
44
+ PRIVATE_IP = re.compile(
45
+ r'\b(?:10\.\d{1,3}\.\d{1,3}\.\d{1,3}'
46
+ r'|192\.168\.\d{1,3}\.\d{1,3}'
47
+ r'|172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}'
48
+ r'|169\.254\.\d{1,3}\.\d{1,3})\b'
49
+ )
50
+
51
  # Secrets — each tuple is (name, compiled regex). Keep these conservative
52
  # enough to avoid mangling ordinary prose but broad enough to catch real keys.
53
  SECRET_PATTERNS = [
 
99
  return "[REDACTED_EMAIL]"
100
  s = EMAIL.sub(_email, s)
101
 
102
+ # Private/internal IPs (redact-only, not treated as a rejectable secret)
103
+ def _ip(m):
104
+ counts["private_ip"] += 1
105
+ return "[REDACTED_IP]"
106
+ s = PRIVATE_IP.sub(_ip, s)
107
+
108
  return s
109
 
110