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/iancoleman/orderedmap
A golang data type equivalent to python's collections.OrderedDict
Retains order of keys in maps
Can be JSON serialized / deserialized
package main
import (
"encoding/json"
"github.com/iancoleman/orderedmap"
)
func main() {
// use New() instead of o := map[string]interface{}{}
o := orderedmap.New()
// use SetEscapeHTML() to whether escape problematic HTML characters or not, defaults is true
o.SetEscapeHTML(false)
// use Set instead of o["a"] = 1
o.Set("a", 1)
// add some value with special characters
o.Set("b", "\\.<>[]{}_-")
// use Get instead of i, ok := o["a"]
val, ok := o.Get("a")
// use Keys instead of for k, v := range o
keys := o.Keys()
for _, k := range keys {
v, _ := o.Get(k)
}
// use o.Delete instead of delete(o, key)
o.Delete("a")
// serialize to a json string using encoding/json
bytes, err := json.Marshal(o)
prettyBytes, err := json.MarshalIndent(o, "", " ")
// deserialize a json string using encoding/json
// all maps (including nested maps) will be parsed as orderedmaps
s := `{"a": 1}`
err := json.Unmarshal([]byte(s), &o)
// sort the keys
o.SortKeys(sort.Strings)
// sort by Pair
o.Sort(func(a *orderedmap.Pair, b *orderedmap.Pair) bool {
return a.Value().(float64) < b.Value().(float64)
})
}
go test
None of the alternatives offer JSON serialization.
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.