Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/eltonjr/go-experiments/decorator-pattern
This is a simple proof-of-concept of an interface calling itself, also known as a Decorator design pattern.
To avoid bloating the real implementation of anything with logs, traces, profiling etc, one could implement the interface adding those decorators just for that, leaving the real implementation cleaner.
It's not unusual to have something like this everywhere in your codebase:
func DoSomething(ctx context.Context) {
var span trace.Span
ctx, span = tracer.Start(ctx, "DoSomething") // instrument with traces
defer span.End()
logger.Debug("at DoSomething") // instrument with log
defer logger.Debug("finished DoSomething")
// now at last do the something it is supposed to do
}
To avoid that, one could implement the DoSomething interface to add traces and logs, and, at the end, call the DoSomething interface again, but now with the real implementation.
type DoSomethinger interface {
DoSomething(ctx context.Context)
}
// DoSomethingDecorator has an DoSomethinger but also implements DoSomethinger
// just to add instrumentation
type DoSomethingDecorator struct {
impl DoSomethinger
}
func (deco DoSomethingDecorator) DoSomething(ctx context.Context) {
var span trace.Span
ctx, span = tracer.Start(ctx, "DoSomething") // instrument with traces
defer span.End()
logger.Debug("at DoSomething") // instrument with log
defer logger.Debug("finished DoSomething")
deco.impl.DoSomething(ctx)
}
// RealImpl also implements DoSomethinger
type RealImpl struct {}
func (real RealImpl) DoSomething(ctx context.Context) {
// just do what it is supposed to do
}
To run the project, use
go run main.go
This will start 2 servers, one with log (using the decorator), and one without it.
Call the endpoints at :8080 to access the server without log, and :8081 to access the server that logs everything
curl -L -X POST 'http://localhost:8080/items' \
-H 'Content-Type: application/json' \
--data-raw '{"id": 2}'
curl -L -X GET 'http://localhost:8080/items/2'
curl -L -X POST 'http://localhost:8081/items' \
-H 'Content-Type: application/json' \
--data-raw '{"id": 3}'
curl -L -X GET 'http://localhost:8081/items/3'
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.