Skip to content

Instantly share code, notes, and snippets.

@phra
Created May 29, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phra/7691e97e2327b024dcc2ae4dc483cd89 to your computer and use it in GitHub Desktop.
Save phra/7691e97e2327b024dcc2ae4dc483cd89 to your computer and use it in GitHub Desktop.
fast-redact vulnerable validator
try {
if (/〇/.test(s)) throw Error()
const proxy = new Proxy({}, {get: () => proxy, set: () => { throw Error() }})
const expr = s.replace(/^\*/, '〇').replace(/\.\*/g, '.〇').replace(/\[\*\]/g, '[〇]')
if (/\/\*/.test(expr)) throw Error()
/* eslint-disable-next-line */
new Script(`
o.${expr}
if ([o.${expr}].length !== 1) throw Error()
`).runInNewContext({o: proxy, 〇: null})
} catch (e) {
throw Error(ERR_INVALID_PATH(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment