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/vporoshok/forms
Generate HTML forms from struct
Just make struct of request form your service handler expect and generate, render, parse, validate and render errors quick and simple. This library provides form-abstraction that can be built manual, reflected from struct tags or pre-generated from struct tags. Forms may be rendered in an HTML presentation with optional renderers (you can create your renderer). Also, forms may be parsed from HTTP request form values or JSON-body. After parsing forms may be used to collect errors (by field) to render in response.
It is often difficult to understand what went wrong in a complex system built with microservices. Sometimes you need to just build request to microservice and look at the result. But microservices may have different and complex interfaces like AMQP, gRPC or something else. In the following of my approach to project architecture (in Russian) business logic shouldn't depend on interface. So it should be easy to provide an alternative interface to service logic. Well, it may be some kind of rest API. But it would be quite good to give a simple HTML interface to the service. But build forms in HTML is a double work. So this library helps to render HTML forms from your Go code like a charm.
The idea of this project is quite simple:
Any form is a data expected by action
We have to describe this data in any case. So why don't we just use this description to build our interface?
See full example in documentation.
type LoginData struct {
Username string `forms:"Email,placeholder(user@example.com),required"`
Password string `forms:",type(password),required"`
RememberMe bool
}
func (srv *Server) login(w http.ResponseWriter, r *http.Request) {
data := LoginData{}
form, err := forms.From(&data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if r.Method == http.MethodPost {
if form.Parse(r) {
// Validate (just dummy example)
if !strings.ContainsRune(data.Username, '@') {
form.AddFieldError("Username", errors.New("should be a valid email"))
}
if data.Password != "password" {
form.AddFormError(errors.New("invalid username or password"))
}
if form.IsValid() {
// do login
}
}
}
if form.IsValid() {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusBadRequest)
}
_ = srv.pageTemplate.Execute(w, form)
}
Architect, conceptions, dependencies. This section should be written after implementation.
This project inspired by next projects:
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.