Socket
Socket
Sign inDemoInstall

fast-redact

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-redact - npm Package Compare versions

Comparing version 1.1.13 to 1.1.14

6

lib/parse.js

@@ -10,4 +10,5 @@ 'use strict'

var wcLen = 0
const secret = paths.reduce(function (o, strPath) {
const secret = paths.reduce(function (o, strPath, ix) {
var path = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ''))
const leadingBracket = ix === 0 && strPath[0] === '['
path = path.map((p) => {

@@ -37,3 +38,4 @@ if (p[0] === '[') return p.substr(1, p.length - 2)

circle: '',
escPath: JSON.stringify(strPath)
escPath: JSON.stringify(strPath),
leadingBracket: leadingBracket
}

@@ -40,0 +42,0 @@ }

@@ -29,4 +29,5 @@ 'use strict'

return Object.keys(secret).map((path) => {
const { escPath } = secret[path]
const { escPath, leadingBracket } = secret[path]
const skip = leadingBracket ? 1 : 0
const delim = leadingBracket ? '' : '.'
const hops = []

@@ -37,7 +38,7 @@ var match

const { index, input } = match
if (index > 0) hops.push(input.substring(0, index - (ix ? 0 : 1)))
if (index > skip) hops.push(input.substring(0, index - (ix ? 0 : 1)))
}
var existence = hops.map((p) => `o.${p}`).join(' && ')
if (existence.length === 0) existence += `o.${path} != null`
else existence += ` && o.${path} != null`
var existence = hops.map((p) => `o${delim}${p}`).join(' && ')
if (existence.length === 0) existence += `o${delim}${path} != null`
else existence += ` && o${delim}${path} != null`

@@ -47,3 +48,3 @@ const circularDetection = `

${hops.reverse().map((p) => `
case o.${p} === censor:
case o${delim}${p} === censor:
secret[${escPath}].circle = ${JSON.stringify(p)}

@@ -56,3 +57,3 @@ break

if (${existence}) {
const val = o.${path}
const val = o${delim}${path}
if (val === censor) {

@@ -62,3 +63,3 @@ secret[${escPath}].precensored = true

secret[${escPath}].val = val
o.${path} = censor
o${delim}${path} = censor
${circularDetection}

@@ -65,0 +66,0 @@ }

@@ -25,6 +25,7 @@ 'use strict'

return paths.map((path) => {
const { circle, escPath } = secret[path]
const { circle, escPath, leadingBracket } = secret[path]
const delim = leadingBracket ? '' : '.'
const reset = circle
? `o.${circle} = secret[${escPath}].val`
: `o.${path} = secret[${escPath}].val`
: `o${delim}${path} = secret[${escPath}].val`
const clear = `secret[${escPath}].val = null`

@@ -31,0 +32,0 @@ return `

@@ -25,3 +25,3 @@ 'use strict'

const proxy = new Proxy({}, {get: () => proxy, set: () => { throw Error() }})
const expr = s.replace(/^\*/, '〇').replace(/\.\*/g, '.〇').replace(/\[\*\]/g, '[〇]')
const expr = (s[0] === '[' ? '' : '.') + s.replace(/^\*/, '〇').replace(/\.\*/g, '.〇').replace(/\[\*\]/g, '[〇]')
if (/\n|\r|;/.test(expr)) throw Error()

@@ -32,4 +32,4 @@ if (/\/\*/.test(expr)) throw Error()

'use strict'
o.${expr}
if ([o.${expr}].length !== 1) throw Error()
o${expr}
if ([o${expr}].length !== 1) throw Error()
})()

@@ -36,0 +36,0 @@ `, createContext({o: proxy, 〇: null}), {

{
"name": "fast-redact",
"version": "1.1.13",
"version": "1.1.14",
"description": "very fast object redaction",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -46,2 +46,4 @@ # fast-redact

Leading brackets are also allowed, for instance `["a"].b.c` will work.
##### Wildcards

@@ -239,3 +241,3 @@

```
199 passing (453.186ms)
224 passing (499.544ms)
```

@@ -242,0 +244,0 @@

@@ -340,3 +340,3 @@ 'use strict'

doesNotThrow(() => {
redact.restore(o)
redact.restore(o)
})

@@ -347,3 +347,2 @@

test('gracefully handles primitives that match intermediate keys in paths', ({end, same}) => {

@@ -725,2 +724,92 @@ const redact = fastRedact({paths: ['a.b.c', 'a.b.c.d'], serialize: false})

end()
})
})
test('supports leading bracket notation', ({end, is}) => {
const redact = fastRedact({paths: ['["a"].b.c']})
const o = {a: {b: {c: 'd'}}}
is(redact(o), `{"a":{"b":{"c":"${censor}"}}}`)
end()
})
test('supports leading bracket notation containing non-legal keyword characters', ({end, is}) => {
const redact = fastRedact({paths: ['["a-x"].b.c']})
const o = {'a-x': {b: {c: 'd'}}}
is(redact(o), `{"a-x":{"b":{"c":"${censor}"}}}`)
end()
})
test('supports single leading bracket', ({end, is}) => {
const censor = 'test'
const redact = fastRedact({paths: ['["a"]'], censor, serialize: false})
is(redact({a: 'a'}).a, censor)
end()
})
test('supports single leading bracket containing non-legal keyword characters', ({end, is}) => {
const censor = 'test'
const redact = fastRedact({paths: ['["a-x"]'], censor, serialize: false})
is(redact({'a-x': 'a'})['a-x'], censor)
end()
})
test('(leading brackets) ultimate wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['bar.baz.*', 'cf.*'], serialize: false})
const bar = {b: 2}
const o = {a: 1, bar, cf: {bar}}
bar.baz = bar
o.bar.baz = o.bar
is(o.bar.baz, bar)
is(o.cf.bar, bar)
redact(o)
is(o.bar.baz, censor)
is(o.cf.bar, censor)
redact.restore(o)
is(o.bar.baz, bar)
is(o.cf.bar, bar)
end()
})
test('(leading brackets) parent wildcards – handles circulars and cross references – restore', ({end, is, same}) => {
const redact = fastRedact({paths: ['["x"].*.baz', '["x"].*.cf.bar'], serialize: false})
const bar = {b: 2}
const o = {x: {a: 1, bar, y: {cf: {bar}}}}
bar.baz = bar
o.x.bar.baz = o.x.bar
is(o.x.bar.baz, bar)
is(o.x.y.cf.bar, bar)
redact(o)
is(o.x.bar.baz, censor)
is(o.x.y.cf.bar, censor)
redact.restore(o)
is(o.x.bar.baz, bar)
is(o.x.y.cf.bar, bar)
end()
})
test('(leading brackets) ultimate wildcards – handles missing paths', ({end, is, same}) => {
const redact = fastRedact({paths: ['["z"].*']})
const o = {a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}}
is(redact(o), JSON.stringify(o))
end()
})
test('(leading brackets) static + wildcards reuse', ({end, is}) => {
const redact = fastRedact({paths: ['["a"].b.c', '["a"].d.*'], serialize: false})
const result = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
is(result.a.b.c, censor)
is(result.a.d.a, censor)
is(result.a.d.b, censor)
is(result.a.d.c, censor)
redact.restore(result)
const result2 = redact({a: {b: {c: 's'}, d: {a: 's', b: 's', c: 's'}}})
is(result2.a.b.c, censor)
is(result2.a.d.a, censor)
is(result2.a.d.b, censor)
is(result2.a.d.c, censor)
redact.restore(result2)
end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc