
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
github.com/dc0d/sector
sector - for Simple Injector - provides a Dependency Injection mechanism for Go.
Put it simply, sector fills pointers with values come from factories. So we have the factory - the constructor (role) - and the injector.
A factory implements the Factory
interface. In it's simplest form, it's just a function with this signature, func(interface{}) bool
and uses the Go's type switch to fill the pointers:
func myFactory(ptr interface{}) bool {
switch x := ptr.(type) {
case *int:
*x = 1001
case *string:
*x = `injected string`
case *Trait:
buffer := Trait{}
*x = buffer
case *Data:
buffer := Data{}
*x = buffer
case *map[string]interface{}:
*x = make(map[string]interface{})
(*x)[`asset`] = `another injected string`
case *SI:
v := SIO{`yet another injected string`}
*x = &v
case *[]int:
*x = []int{1, 2, 3}
default:
// this factory does not fill pointers of this type
return false
}
return true
}
Then we use this factory in our injector to fill in the fields of a struct.
dj := NewInjector(FactoryFunc(genericFactory))
Now we use this injector to inject desired values into struct's fields.
var s Sample
dj.Inject(&s)
Fields that are tagged with inject:"+"
will get filled with proper value from the factory. Fields tagged with inject:"*"
will get filled recursively down the tree.
type Sample struct {
Trait `inject:"*"` // inject field, recursively, all down the data tree
N int `inject:"+"` // inject field
S string `inject:"+"`
D Data `inject:"*"`
NL []int `inject:"+"`
Map map[string]interface{} `inject:"+"`
DataPtr *Data `inject:"*"`
SI SI `inject:"+"`
}
It is also possible to inject arguments of a function using the Invoke
method.
FAQs
Unknown package
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
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.