Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
postcss-mangle-css-class
Advanced tools
Minifies and obfuscates the class names without any modern css modules.
The plugin will generate optimized class name. Configure minimally as follows:
import postCSSMangleCSSClass from "postcss-mangle-css-class";
export default {
plugins: [
postCSSMangleCSSClass({
CSSinput: "./style.css",
export: {
JSONFile: "./.mangle-css-class/classes.json",
JSFile: "./.mangle-css-class/classes.js"
},
classNameRename: "[name]_[hash]",
getOutput(renamed, excluded) {
console.log("output", { renamed, excluded });
},
}),
],
};
const options = {
enable: true,
cwd: process.cwd(),
CSSinput: "",
classNameRename: "[name]_[hash]",
hash: {
type: "random",
minLength: 5,
salt: "",
},
exclude: {
classNames: [],
files: [],
},
CSSextensions: [".css", ".sass", ".scss", ".less", ".styl"],
export: {
JSONFile: "./.mangle-css-class/classes.json", JSFile: "./.mangle-css-class/classes.js",
rewrite: false,
},
getOutput(renamed, excluded) {}
};
Enable/disable plugin. Default: true
The current working directory. Default: process.cwd()
Establishes which CSS files should be analyzed. e.g: './app.css'
Set an interpolated string to rename CSS classes. Placeholders compatible:
[name]
is the class name[hash]
is the hash generate. You can set the type to hash.type
and the minimum length hash.minLength
and optionally hash.salt
e.g.: prefix_[name]_[hash]
Sets the hash type. Possible values: none
,random
,salt
. Default: random
none
no hash will be applied.random
generates an unpredictable random hash.salt
generates a predictable random hash. If you need it to be unique; for example, in each project, you can configure: hash.salt
Set the minimum hash length. Default: 5
If you need to generate unique hashes for each project, you can set salt
different in each one. e.g: myProject1
. It is only applicable if you have defined hash.type
:salt
CSS classes that will not be replaced. e.g: ["card",/text-/g]
CSS classes that are used or found in these files will be ignored. e.g: ["./css-ignore.css","./js/*.js"]
Establishes which files should be parsed as style sheets. Usually used if you set exclude.files
. Default: [".css", ".sass", ".scss", ".less", ".styl"]
The path of the file where the replaced classes will be saved. Default: "./.mangle-css-class/classes.json"
. The file will have the following structure:
{
"card":"ahJ25g",
"card-body":"Awk1JO"
}
The path of the file where the replaced classes will be saved in format ESM
. Default: "./.mangle-css-class/classes.js"
. The file will have the following structure:
const card = "ahJ25g";
const card_body = "Awk1JO";
export default {card,card_body}
Sets whether to rewrite previously generated files.
Default: false
.
A callback that passes the renamed and excluded CSS classes.
Required to start; It should commonly be called before any script.
const options_ = {
cwd: process.cwd(),
CSSinput: "",
postcss: null,
context: {},
};
cwd
the current working directory. Default process.cwd()
CSSinput
CSS files that are allowed to be analyzed. e.g: './app.css'
postcss
PostCSS config. Default: load postcss.config.js
in the root projecte.g:
import initMangleCSSClass from "postcss-mangle-css-class/init";
initMangleCSSClass({
CSSinput: "./style.css"
});
Each package has its own particularity, which is why we have prepared the following examples of how you could use this plugin. For more details:
vite
...You can use the plugin vite-plugin-replace-mangle-css-class
Documentation
Before:
// postcss.config.js
import postCSSMangleCSSClass from "postcss-mangle-css-class";
export default {
plugins: [
postCSSMangleCSSClass({
CSSinput: ["./page-1.css","./page-2.css","./page-3.css"]
}),
],
};
After:
// postcss.config.js
import postCSSMangleCSSClass from "postcss-mangle-css-class";
export default {
plugins: [
postCSSMangleCSSClass({
CSSinput: "./all-pages.css"
}),
],
};
This project is under license from MIT. For more details, see the LICENSE file.
FAQs
Minifies and obfuscates the class names without any modern css modules.
The npm package postcss-mangle-css-class receives a total of 3 weekly downloads. As such, postcss-mangle-css-class popularity was classified as not popular.
We found that postcss-mangle-css-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.