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.
A small Ruby gem to generate YouTube-like ids from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
hashids (Hash ID's) creates short, unique, decodable hashes from unsigned integers.
(NOTE: This is NOT a true cryptographic hash, since it is reversible)
It was designed for websites to use in URL shortening, tracking stuff, or making pages private (or at least unguessable).
This algorithm tries to satisfy the following requirements:
Instead of showing items as 1
, 2
, or 3
, you could show them as jR
, k5
, and l5
.
You don't have to store these hashes in the database, but can encode + decode on the fly.
All integers need to be greater than or equal to zero.
Add this line to your application's Gemfile:
gem 'hashids'
And then execute:
$ bundle
Or install it yourself as:
$ gem install hashids
You can pass a unique salt value so your hashes differ from everyone else's. I use this is my salt as an example.
hashids = Hashids.new("this is my salt")
hash = hashids.encode(12345)
hash
is now going to be:
NkK9
Notice during decoding, same salt value is used:
hashids = Hashids.new("this is my salt")
numbers = hashids.decode("NkK9")
numbers
is now going to be:
[ 12345 ]
Decoding will not work if salt is changed:
hashids = Hashids.new("this is my pepper")
numbers = hashids.decode("NkK9")
numbers
is now going to be:
[]
hashids = Hashids.new("this is my salt")
hash = hashids.encode(683, 94108, 123, 5)
hash
is now going to be:
aBMswoO2UB3Sj
hashids = Hashids.new("this is my salt")
numbers = hashids.decode("aBMswoO2UB3Sj")
numbers
is now going to be:
[ 683, 94108, 123, 5 ]
Here we encode integer 1, and set the minimum hash length to 8 (by default it's 0 -- meaning hashes will be the shortest possible length).
hashids = Hashids.new("this is my salt", 8)
hash = hashids.encode(1)
hash
is now going to be:
gB0NV05e
hashids = Hashids.new("this is my salt", 8)
numbers = hashids.decode("gB0NV05e")
numbers
is now going to be:
[ 1 ]
Here we set the alphabet to consist of: "abcdefghijkABCDEFGHIJK12345"
hashids = Hashids.new("this is my salt", 0, "abcdefghijkABCDEFGHIJK12345")
hash = hashids.encode(1, 2, 3, 4, 5)
hash
is now going to be:
dEc4iEHeF3
The primary purpose of hashids is to obfuscate ids. It's not meant or tested to be used for security purposes or compression. Having said that, this algorithm does try to make these hashes unguessable and unpredictable:
hashids = Hashids.new("this is my salt")
hash = hashids.encode(5, 5, 5, 5)
You don't see any repeating patterns that might show there's 4 identical numbers in the hash:
1Wc8cwcE
Same with incremented numbers:
hashids = Hashids.new("this is my salt")
hash = hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
hash
is now going to be:
kRHnurhptKcjIDTWC3sx
hashids = Hashids.new("this is my salt")
hashids.encode 1 #=> NV
hashids.encode 2 #=> 6m
hashids.encode 3 #=> yD
hashids.encode 4 #=> 2l
hashids.encode 5 #=> rD
hashids = Hashids.new("this is my salt")
hash = hashids.encode_hex('DEADBEEF')
hash
is now going to be:
kRNrpKlJ
hashids = Hashids.new("this is my salt")
hex_str = hashids.decode_hex("kRNrpKlJ")
hex_str
is now going to be:
DEADBEEF
1.0.6
must_equal
and must_raise
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
validate_alphabet
now run before setting up seps & guards1.0.0
encrypt
changed to encode
encrypt_hex
changed to encode_hex
decrypt
changed to decode
decrypt_hex
changed to decode_hex
0.3.0
encrypt_hex
and decrypt_hex
0.0.3
Hashids.new.encrypt(91) #=> "kBy"
)tr/delete
over gsub
, scan
over split
)0.0.2
0.0.1
Follow me @peterhellberg
MIT License. See the LICENSE.txt
file.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that hashids demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.