From a642e929ff9ca414a3ad365e218cb7a8a7eb7a51 Mon Sep 17 00:00:00 2001 From: fraxken Date: Fri, 16 Aug 2024 19:26:15 +0200 Subject: [PATCH] fix(Deobfuscator): return if Node is null in extractCounterIdentifiers --- src/Deobfuscator.js | 3 +++ ...fuscator-function-declaration-id-null.spec.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/issues/295-deobfuscator-function-declaration-id-null.spec.js diff --git a/src/Deobfuscator.js b/src/Deobfuscator.js index 580d75c..f1ad6cf 100644 --- a/src/Deobfuscator.js +++ b/src/Deobfuscator.js @@ -63,6 +63,9 @@ export class Deobfuscator { * @param {*} node */ #extractCounterIdentifiers(nc, node) { + if (node === null) { + return; + } const { type } = nc; switch (type) { diff --git a/test/issues/295-deobfuscator-function-declaration-id-null.spec.js b/test/issues/295-deobfuscator-function-declaration-id-null.spec.js new file mode 100644 index 0000000..52ab4f1 --- /dev/null +++ b/test/issues/295-deobfuscator-function-declaration-id-null.spec.js @@ -0,0 +1,16 @@ +// Import Node.js Dependencies +import { test } from "node:test"; + +// Import Internal Dependencies +import { AstAnalyser } from "../../index.js"; + +/** + * @see https://github.com/NodeSecure/js-x-ray/issues/295 + */ +test("Deobfuscator.#extractCounterIdentifiers should not throw if FunctionDeclaration id is null", () => { + new AstAnalyser().analyse(` + export default async function (app) { + app.loaded = true + } + `); +});