ag-common 0.0.855 → 0.0.856

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.
@@ -48,8 +48,37 @@ function redactString(str) {
48
48
  ret = ret.replace(/(REDIS_URL["\s]*[:=]["\s]*)([^",\s}]+)/gi, '$1<redacted>');
49
49
  ret = ret.replace(/(SMTP_PASSWORD["\s]*[:=]["\s]*)([^",\s}]+)/gi, '$1<redacted>');
50
50
  ret = ret.replace(/(ENCRYPTION_KEY["\s]*[:=]["\s]*)([^",\s}]+)/gi, '$1<redacted>');
51
+ // High entropy strings and long base64-like strings
52
+ ret = ret.replace(/\b([a-zA-Z0-9+/=_-]{20,})\b/g, (match) => {
53
+ // If it ends with ==, it's almost certainly a base64 string provided it is long enough
54
+ // We use a slightly higher length threshold for this specific check to be safe
55
+ if (match.endsWith('==') && match.length > 30) {
56
+ return '<redacted>';
57
+ }
58
+ // Check entropy for other long strings
59
+ if (getShannonEntropy(match) > 4.5) {
60
+ return '<redacted>';
61
+ }
62
+ return match;
63
+ });
51
64
  return ret;
52
65
  }
66
+ function getShannonEntropy(str) {
67
+ var _a;
68
+ const len = str.length;
69
+ if (len === 0)
70
+ return 0;
71
+ const frequencies = new Map();
72
+ for (const char of str) {
73
+ frequencies.set(char, ((_a = frequencies.get(char)) !== null && _a !== void 0 ? _a : 0) + 1);
74
+ }
75
+ let entropy = 0;
76
+ for (const count of frequencies.values()) {
77
+ const p = count / len;
78
+ entropy -= p * Math.log2(p);
79
+ }
80
+ return entropy;
81
+ }
53
82
  function redactObject(ob) {
54
83
  if (typeof ob === 'string') {
55
84
  return redactString(ob);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.855",
2
+ "version": "0.0.856",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",