Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Non-AST Based] Failed to capture the correct content if there is no "{" and "}" wrapped outside the .jsx obfuscation marker. #41

Open
5 of 9 tasks
soranoo opened this issue May 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@soranoo
Copy link
Owner

soranoo commented May 24, 2024

Note

This only affects the non-AST based obfuscation (i.e. enableJsAst: false) with enableMarkers: false

Type

  • Incorrect Class Name Extraction
  • Incorrect JavaScript Obfuscation
  • Incorrect HTML Obfuscation
  • Incorrect CSS Obfuscation
  • Others

Checklist

  1. Updated the package to the latest version
  2. Read all documentation
  3. No related issue
  4. Meaningful issue title

Environment

  • Package Version: v2.2.16
  • Node Version: v20.11.1

Describe the bug
Failed to capture the correct content if there is no "{" and "}" wrapped outside the .jsx obfuscation marker.

To Reproduce
Steps to reproduce the behavior:

import fs from "fs";
import path from "path";
import { obfuscateJs } from "./src/handlers/js";

const jsonDataPath = path.join(__dirname, "css-obfuscator");
const jsonData = {};
fs.readdirSync(jsonDataPath).forEach((file: string) => {
    const filePath = path.join(jsonDataPath, file);
    const fileData = JSON.parse(fs.readFileSync(filePath, "utf-8"));
    Object.assign(jsonData, fileData);
});

const obsJs = obfuscateJs(`b = ({ className: s = "", children: t, ...r }) => e.jsx(l, { ...r, className: "block w-full px-4 py-2 text-start text-sm leading-5 text-gray-700 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 transition duration-150 ease-in-out " + s, children: t, }); function v({ active: s = !1, className: t = "", children: r, ...n }) { return e.jsx(l, { ...n, className: "block w-full px-4 py-2 text-start text-sm" + (s ? "leading-5" : "text-gray-700") + t, children: r, }); }`
, ".jsx", jsonData, "fake_path", [], false)
console.log(obsJs);

Expected behavior
Obfuscate all classNames.

Screenshots
image

Code

// Failed
b = ({ className: s = "", children: t, ...r }) =>
    e.jsx(l, {
        ...r,
        className:
            "block w-full px-4 py-2 text-start text-sm leading-5 text-gray-700 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 transition duration-150 ease-in-out " +
            s,
        children: t,
    });

// Success
function v({ active: s = !1, className: t = "", children: r, ...n }) {
  return e.jsx(l, {
      ...n,
      className:
          "ca1or cctlf ccn3e cfg9y cevl3 cevd7 c7vyf c8r2h cdon0 ce1sz cfuim carw5 " +
          (s
              ? "ca4kf cf4p6 cejum "
              : "ceesc ccfge ca6vp caers cb5z5 ccuy9 ") +
          t,
      children: r,
  });
}

Config

module.exports = {
  enable: true,
  mode: "random", // random | simplify | simplify-seedable
  refreshClassConversionJson: false, // recommended set to true if not in production
  allowExtensions: [".jsx", ".tsx", ".js", ".ts", ".html", ".rsc"],
  buildFolderPath: "public/build/assets", // Build folder of your project.
};

Solution

  1. Set enableJsAst: true in the config.
@soranoo soranoo added the bug Something isn't working label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant