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/elliotchance/orderedmap
An *OrderedMap
is a high performance ordered map that maintains amortized O(1)
for Set
, Get
, Delete
and Len
:
import "github.com/elliotchance/orderedmap/v2"
func main() {
m := orderedmap.NewOrderedMap[string, any]()
m.Set("foo", "bar")
m.Set("qux", 1.23)
m.Set("123", true)
m.Delete("qux")
}
Note: v2 requires Go v1.18 for generics. If you need to support Go 1.17 or below, you can use v1.
Internally an *OrderedMap
uses the composite type
map combined with a
trimmed down linked list to maintain the order.
Be careful using Keys()
as it will create a copy of all of the keys so it's
only suitable for a small number of items:
for _, key := range m.Keys() {
value, _:= m.Get(key)
fmt.Println(key, value)
}
For larger maps you should use Front()
or Back()
to iterate per element:
// Iterate through all elements from oldest to newest:
for el := m.Front(); el != nil; el = el.Next() {
fmt.Println(el.Key, el.Value)
}
// You can also use Back and Prev to iterate in reverse:
for el := m.Back(); el != nil; el = el.Prev() {
fmt.Println(el.Key, el.Value)
}
The iterator is safe to use bidirectionally, and will return nil
once it goes
beyond the first or last item.
If the map is changing while the iteration is in-flight it may produce unexpected behavior.
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.