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.
tree-selector
Advanced tools
build a matching or query function for CSS selectors for any nested object structure!
import { createQuerySelector, createMatches } from 'tree-selector';
const options = {
tag: n => n.tagName,
contents: n => n.innerText,
id: n => n.id,
class: n => n.className,
parent: n => n.parentElement,
children: n => n.childNodes,
attr: (n, attr) => n.getAttribute(attr)
};
const querySelector = createQuerySelector(options);
const matches = createMatches(options);
const selector = 'span.mySpan';
const element = document.getElementsByClassName('span')[0]
if(matches(selector, element)) {
// there are elements matching the selector
} else {
// no elements found
}
//Also possible, but less efficient
if(querySelector(selector, element).length > 0) {
// there are elements found
}
Configure tree-selector
for the nested object structure you'll want to match against.
Configure a matches
function for a node in your tree structure. (This is used internally by createQuerySelector
)
options
are an object of lookup functions for queried nodes. You only need to provide the configuration necessary for the selectors you're planning on creating.
(If you're not going to use #id
lookups, there's no need to provide the id
lookup in your options.)
tag
: Extract tag information from a node for div
style selectors.contents
: Extract text information from a node, for :contains(xxx)
selectors.id
: Extract id for #my_sweet_id
selectors.class
: .class_name
parent
: Used for sibling selectorschildren
: Used to traverse from a parent to its children for sibling selectors div + span
, a ~ p
.attr
: Used to extract attribute information, for [attr=thing]
style selectors.:first-child
:last-child
:nth-child
:empty
:root
:contains(text)
[attr=value]
: Exact match[attr]
: Attribute exists and is not false-y.[attr$=value]
: Attribute ends with value[attr^=value]
: Attribute starts with value[attr*=value]
: Attribute contains value[attr~=value]
: Attribute, split by whitespace, contains value.[attr|=value]
: Attribute, split by -
, contains value.FAQs
Use CSS selectors to match nodes in a custom object tree
The npm package tree-selector receives a total of 1,644 weekly downloads. As such, tree-selector popularity was classified as popular.
We found that tree-selector 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.