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.
branded-types
Advanced tools
Flippin' great branded types for TypeScript!
Use them like opaque types in Flow, except you get to control visibility.
Define a branded type:
import {Branded} from 'branded-types'
export class OrderId extends Branded<string, 'my-package.OrderId'>() {}
Import and use it
import {OrderId} from './other-module';
OrderId.brand('someUuid') === 'someString' // error
Want to hide the branding and un-branding functions?
import { Branded } from "branded-types";
namespace my {
export class OrderId extends Branded<string, 'my-package.OrderId'>() {}
}
export function safeCreateId() {
return my.OrderId.brand('x')
}
export type OrderId = my.OrderId;
The other module can only use the safe ID creation functions now:
import {safeCreateId, OrderId} from './other-module';
safeCreateId() == 'someString'; // error
let m: Map<OrderId, string> = new Map;
m.set(safeCreateId(), '1');
m.set('someString', '2'); // error
This condition will always return 'false' since
the types 'string' and 'OrderId' have no overlap.
and the incorrect map insertion above produces the error:
Argument of type 'string' is not assignable to parameter of type 'OrderId'.
+
, its not going to work. You have to use an explicit cast to the source type via e.g.
String(brandedVal)
or Number(brandedVal)
etc, then perform the operationFAQs
Flippin' great branded types for TypeScript!
The npm package branded-types receives a total of 1 weekly downloads. As such, branded-types popularity was classified as not popular.
We found that branded-types 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.