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.
posthtml-transform
Advanced tools
PostHTML plugin to add/modify tags attributes.
posthtml([
transform({ attr: 'fill', value: 'red' })
]);
Input
<svg>
<path />
</svg>
Output
<svg fill="red">
<path fill="red" />
</svg>
npm install posthtml-transform
const { readFileSync } = require('fs');
const posthtml = require('posthtml');
const transform = require('posthtml-transform');
const input = readFileSync('input.html');
posthtml()
.use(transform(options))
.process(input)
.then(({ html }) => {
console.log(html);
});
Plugin accepts one or array of transformers. Transformer is an object with following fields:
attr
- name of tag attribute to modify. If doesn't exists it will be created. Should be used in combination with value
.value
- attribute value to set. Should be used in combination with attr
.tag
- tag name to set. Should be used in combination with selector
(or without, if you want to rename all tags :).selector
(optional, *
by default) - CSS selector to find nodes. If not presented all nodes will be selected.
Complete list of supported selectors see on posthtml-match-helper documentation.
Here is a short list:
div
.#id
..class
, .class1.class2
.[attr=value]
, [attr!=value]
etc.path, .class, #id
.
Nested selectors (g path
, g > path
) are not supported.Example
transform({ attr: 'fill', value: 'red' }); // add fill="red" to all nodes
transform({ attr: 'fill', value: 'red', selector: 'path' }); // add fill="red" only to paths
transform({ attr: 'stroke', value: 'black', selector: '#logo' }); // add `stroke` attr to node with id="logo"
transform({ selector: 'g', tag: 'symbol' }); // rename all <g> to <symbol>
It is also possible to pass URL query params string to plugin. It will be parsed and converted to transformer params, e.g:
transform('fill=red'); // => { attr: 'fill', value: 'red' }
transform('fill=red&20path'); // => { attr: 'fill', value: 'red, selector: 'path' }
Parameter value has following syntax: attr_name=attr_value optional_selector
.
Parameters can be combined, eg fill=red&stroke=black
.
Examples:
fill=red
fill=red path
fill=red .class
fill=red #id, black .class
fill=red #id&stroke=black .class
FAQs
PostHTML plugin to add/modify tags and attributes
The npm package posthtml-transform receives a total of 7,720 weekly downloads. As such, posthtml-transform popularity was classified as popular.
We found that posthtml-transform 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.
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.