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.
Simple utils to pack (and unpack) arrays and strings to a flat object.
Status: Stable Please report any issues 🐛 Made possible by my Sponsor Program 💖 Follow me @harlan_zw 🐦 • Join Discord for help |
The zhead package provides a flat-object style API for HTML <meta>
tags,
to make this happen we need to pack and unpack arrays and strings to a flat object.
For example, the following object:
{
"viewport": {
"content": {
"width": "device-width",
"initial-scale": "1"
}
}
}
Can be packed to the below (and vice versa):
<meta name="viewport" content="width=device-width, initial-scale=1">
For an example see useSeoMeta.
key
dot.notation
These utils were meant to be fully typed, but I struggled with the implementation. If you want a fun TypeScript challenge then please open a PR :).
npm install --save-dev packrup
# Using yarn
yarn add --dev packrup
Arguments
input - array
The array to pack
options - { key: string | string[], value: string | string[] }
The options to use to resolve the key and value. By default, will choose first 2 keys of an object.
import { packArray } from 'packrup'
packArray([
{ 'http-equiv': 'content-security-policy', 'content': 'content-src none' }
])
// {
// 'content-security-policy': 'content-src none',
// }
Arguments
input - object
The record to pack.
options - { key: string | string[], value: string | string[] }
The options to use to resolve the key and value. By default, will choose first 2 keys of an object.
import { packObject } from 'packrup'
packObject({
image: {
src: {
'1x': 'https://example.com/image.png',
'2x': 'https://example.com/image@2x.png'
},
alt: 'Example Image'
},
}, {
key: 'image.src.1x',
value: 'image.alt'
})
// {
// "https://example.com/image.png": "Example Image",
// }
import { packString } from 'packrup'
const head = packString('src="https://example.com/image.jpg" width="800" height="600"')
// {
// "height": "600",
// "src": "https://example.com/image.jpg",
// "width": "800",
// }
Arguments
input - array
The array to pack
options - { key: string | string[], value: string | string[] }
The options to use to resolve the key and value. By default, will choose first 2 keys of an object.
import { unpackToArray } from 'packrup'
unpackToArray({
'content-security-policy': 'content-src none',
}, { key: 'http-equiv', value: 'content' })
Arguments
input - object
The record to unpack to a string.
options
export interface TransformValueOptions {
entrySeparator?: string
keyValueSeparator?: string
wrapValue?: string
resolve?: (ctx: { key: string, value: unknown }) => string | void
}
import { unpackToString } from 'packrup'
unpackToString({
'noindex': true,
'nofollow': true,
'max-snippet': 20,
'maxi-image-preview': 'large',
}, {
resolve({ key, value }) {
if (typeof value === 'boolean')
return `${key}`
},
keyValueSeparator: ':',
entrySeparator: ', ',
})
// "noindex, nofollow, max-snippet:20, maxi-image-preview:large"
MIT License © 2022-PRESENT Harlan Wilton
FAQs
Node Schema.org for Simple and Automated Google Rich Results
The npm package packrup receives a total of 15,891 weekly downloads. As such, packrup popularity was classified as popular.
We found that packrup demonstrated a healthy version release cadence and project activity because the last version was released less than 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.