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.
github.com/frozzare/go-httpapi
A http router for building http apis in Go based on httprouter and alice.
The router works almost the same way as httprouter does with some changes:
HandleFunc
has two arguments instead of three (request and params).HandleFunc
returns the data and/or a error that the response handle will handle.HandleFunc2
has one argument instead of three (request).HandleFunc3
has one argument instead of three (params).HandleFunc4
has zero arguments instead of three.httpapi.Router
struct as httprouter.Router
has, e.g HandlerFunc
does not exist.go get -u github.com/frozzare/go-httpapi
Example code:
router := httpapi.NewRouter()
router.Get("/hello/:name", func(r *http.Request, ps httpapi.Params) (interface{}, interface{}) {
return map[string]string{
"hello": ps.ByName("name"),
}, nil
})
http.Handle("/", router)
http.ListenAndServe(":3000", nil)
Example response:
GET /hello/fredrik
{
"hello": "fredrik"
}
To configure httprouter you just pass it as argument to NewRouter
:
router := httpapi.NewRouter(&httprouter.Router{
RedirectTrailingSlash: true,
})
To modify the response handle that takes in HandleFunc
, HandleFunc2
and HandleFunc3
is wrapped with HandleFunc
:
router := httpapi.NewRouter()
router.ResponseHandle = func(fn httpapi.HandleFunc) httpapi.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httpapi.Params) {
data, out := fn(r, ps)
// and so on...
}
}
Both return values are returned as interfaces to support more than just than the error type.
router := httpapi.NewRouter()
// with standard http handler.
router.Use(func(h http.Handler) http.Handler {
fmt.Println("Hello, world")
return h
})
// with httprouter's handle.
router.Use(func(h httpapi.Handle) httpapi.Handle {
fmt.Println("Hello, world")
return h
})
MIT © Fredrik Forsmo
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
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.