Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
postcss-prefixwrap
Advanced tools
A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
A PostCSS plugin which prepends a selector to CSS styles to constrain their effect on parent elements in a page.
Supports | Versions |
---|---|
NodeJS | v18 , v19 , v20 , v21 |
PostCSS | v7 , v8 |
⚠️ PostCSS v7 support is no longer validated in automated test cases, and will be removed entirely in a future release.
⚠️ These instructions are only for this plugin. See the PostCSS website for framework information.
Package Manager | Command |
---|---|
NPM | npm install postcss-prefixwrap --save-dev --save-exact |
PNPM | pnpm add postcss-prefixwrap --save-dev --save-exact |
Yarn | yarn add postcss-prefixwrap --dev --exact |
Add to your PostCSS configuration.
const PostCSS = require("gulp-postcss");
const PrefixWrap = require("postcss-prefixwrap");
PostCSS([PrefixWrap(".my-custom-wrap")]);
Add the container to your markup.
<div class="my-custom-wrap"><!-- Your existing markup. --></div>
View your CSS, now prefix-wrapped.
Before
p {
color: red;
}
body {
font-size: 16px;
}
After
.my-custom-wrap p {
color: red;
}
.my-custom-wrap {
font-size: 16px;
}
The minimal required configuration is the prefix selector, as shown in the above example.
PrefixWrap(".my-custom-wrap");
You may want to exclude some selectors from being prefixed, this is enabled using the ignoredSelectors
option.
PrefixWrap(".my-custom-wrap", {
ignoredSelectors: [":root", "#my-id", /^\.some-(.+)$/],
});
You may want root tags, like body
and html
to be converted to classes, then prefixed, this is enabled using
the prefixRootTags
option.
PrefixWrap(".my-container", {
prefixRootTags: true,
});
With this option, a selector like html
will be converted to .my-container .html
, rather than the
default .my-container
.
In certain scenarios, you may only want PrefixWrap()
to wrap certain CSS files. This is done using the whitelist
option.
⚠️ Please note that each item in the
whitelist
is parsed as a regular expression. This will impact how file paths are matched when you need to support both Windows and Unix like operating systems which use different path separators.
PrefixWrap(".my-custom-wrap", {
whitelist: ["editor.css"],
});
In certain scenarios, you may want PrefixWrap()
to exclude certain CSS files. This is done using the blacklist
option.
⚠️ Please note that each item in the
blacklist
is parsed as a regular expression. This will impact how file paths are matched when you need to support both Windows and Unix like operating systems which use different path separators.
If
whitelist
option is also included,blacklist
will be ignored.
PrefixWrap(".my-custom-wrap", {
blacklist: ["colours.css"],
});
When writing nested css rules, and using a plugin like postcss-nested to compile them, you will want to ensure that the nested selectors are not prefixed. This is done by defining the nested
property and setting the value to the selector prefix being used to represent nesting, this is most likely going to be "&"
.
PrefixWrap(".my-custom-wrap", {
nested: "&",
});
As an example, in the following CSS that contains nested selectors.
.demo {
&--lite {
color: red;
}
}
❌ Without the nested
configuration option defined:
.my-custom-wrap .my-custom-wrap .demo--lite {
color: red;
}
✅ With the tested
configuration defined:
.my-custom-wrap .demo--lite {
color: red;
}
PostCSS Prefix Wrap can be used to solve multiple different problems. The following articles give some concrete examples:
Read our Contributing Guide to learn more about how to contribute to this project.
Read our Security Guide to learn how security is considered during the development and operation of this plugin.
The MIT License is used by this project.
FAQs
A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
The npm package postcss-prefixwrap receives a total of 51,147 weekly downloads. As such, postcss-prefixwrap popularity was classified as popular.
We found that postcss-prefixwrap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.