Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
An utility used by Lebab for complex matching of AST nodes.
The package exports 4 curried functions:
matches :: Pattern -> Obj -> (Bool|Obj)
extract :: Name -> Pattern -> Obj -> (Bool|Obj)
extractAny :: Name -> Obj -> (Bool|Obj)
matchesLength :: Pattern -> Array -> (Bool|Obj)
For details, just read the source, it's really small.
Alternatively, read how Lebab uses this for patterns in syntax trees.
import {matches, matchesLength, extract} from "f-matches";
// Function for matching string literal
const isStringLiteral = matches({
"type": "Literal",
// Unlike in Lodash.matches(),
// we can provide a function to assert if object field matches.
"value": (v) => typeof v === 'string',
});
// Function for matching: <local> = require(<source>)
const isRequireDeclarator = matches({
"type": "VariableDeclarator",
// Store the matching identifier under key: "local"
"id": extract("local", {
"type": "Identifier",
}),
"init": {
"type": "CallExpression",
"callee": {
"type": "Identifier",
"name": "require"
},
"arguments": matchesLength([
// Store the matching string literal under key: "source"
extract("source", isStringLiteral),
]),
},
});
// Function for matching: var <local> = require(<source>)
const isRequire = matches({
"type": "VariableDeclaration",
// Match array of exactly 1 element (not 1 or more elements, which is the default)
"declarations": matchesLength([
isRequireDeclarator,
]),
"kind": "var",
});
// Transform require() call to ES6 import statement.
estraverse.replace(ast, {
enter(node) {
const match = isRequire(node);
if (match) {
return {
"type": "ImportDeclaration",
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"local": match.local
}
],
"source": match.source
};
}
}
});
FAQs
Composable version of Lodash.matches()
The npm package f-matches receives a total of 3,917 weekly downloads. As such, f-matches popularity was classified as popular.
We found that f-matches 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.