next-css-obfuscator: [BUG] `dark` and `light` in [data-theme] attribute of tag were detected as className
Type
- Incorrect Class Name Extraction
- Incorrect JavaScript Obfuscation
- Incorrect HTML Obfuscation
- Incorrect CSS Obfuscation
- Others
Checklist
- Updated the package to the latest version
- Read all documentation
- No related issue
- Meaningful issue title
Environment
- Package Version: v.2.2.10
- Node Version: v.20.10.0
Describe the bug
dark and light in [data-theme] attribute of <html> tag were detected as className
To Reproduce Steps to reproduce the behavior:
- Use this package https://www.npmjs.com/package/next-app-theme
- Check out the
./src/theme-script.tsx
type Theme = "dark" | "light";
declare global {
interface Window {
__theme: Theme;
__onThemeChange: (theme: Theme) => void;
__setPreferredTheme: (theme: Theme) => void;
}
}
const code = function () {
window.__onThemeChange = function () {};
function setTheme(newTheme: Theme) {
// document.documentElement.classList.remove(window.__theme);
window.__theme = newTheme;
preferredTheme = newTheme;
document.documentElement.dataset.theme = newTheme;
window.__onThemeChange(newTheme);
// document.documentElement.classList.add(newTheme);
}
var preferredTheme;
try {
preferredTheme = localStorage.getItem("theme") as Theme;
} catch (err) {}
window.__setPreferredTheme = function (newTheme: Theme) {
setTheme(newTheme);
try {
localStorage.setItem("theme", newTheme);
} catch (err) {}
};
var darkQuery = window.matchMedia("(prefers-color-scheme: dark)");
darkQuery.addEventListener("change", function (e) {
window.__setPreferredTheme(e.matches ? "dark" : "light");
});
setTheme(preferredTheme || (darkQuery.matches ? "dark" : "light"));
};
const getTheme = `(${code})();`;
export function ThemeScript() {
return <script dangerouslySetInnerHTML={{ __html: getTheme }} />;
}
Expected behavior
[data-theme] is not a className so… dark and light in [data-theme]="dark" or [data-theme]="light" is shouldn’t be obfuscated.
Screenshots
First load on the website maybe was right, but try add a toggle and press it:
In conversion.json:
Config
module.exports = {
enable: true,
mode: "random",
buildFolderPath: ".next",
classConversionJsonFolderPath: "./css-obfuscator",
refreshClassConversionJson: false,
classLength: 6,
classPrefix: "n",
classSuffix: "",
classIgnore: ["no-transition", "opa-hidden", /nprogress*/, /__.*/, /os-*/],
allowExtensions: [".jsx", ".tsx", ".js", ".ts", ".html", ".rsc"],
contentIgnoreRegexes: [/\.jsxs\)\("\w+"/g],
whiteListedFolderPaths: [],
blackListedFolderPaths: ["./.next/cache", "./src", "./public", "./tests"],
enableMarkers: false,
markers: ["obf"],
removeMarkersAfterObfuscated: true,
removeOriginalCss: true,
generatorSeed: "84817818898",
//! Experimental feature (Alpha)
enableJsAst: false,
logLevel: "info",
};
Related files
Obfuscated version:
97fb199871848870.css.txt
Demos (if any) N/A
Additional context …
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (7 by maintainers)
Commits related to this issue
- Fixed #25 & Replaced Jest with Vitest — committed to soranoo/next-css-obfuscator by soranoo 3 years ago
- Removed #25 's update — committed to soranoo/next-css-obfuscator by soranoo 3 years ago
- Reintroduced HTML AST Based Replace Strategy #25 — committed to soranoo/next-css-obfuscator by soranoo 3 years ago
Im still working on it.