
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@swapnil-pando/url-shortening
Advanced tools
A URL shortener using SHA1 encryption with no external api
This is an implementation of a URL Shortener Implementation without use of any external API using SHA1 encryption.
The long URL which will be given to us will be in the format of
https://localhost:5050/track-link/A-23-Depot-Z-M-01?id=${uuid}"
uuid is unique identifier of 36 characters
The problem statement is to convert this long url into a shortened url. Whenever we click on this shortened url , it should redirect us to the long url and eventually to the webpage that the long url is directing to.
We want our shortened url to be of length ≤ 7.
Character set of our shortened url includes [A-Z], [a-z], [0–9] which is 26 + 26 + 10 = 62 characters.
So with this we can have 62 ^ 7 = 35 billion unique urls. And this is the reason why we will be using base-62 encryption as well in our implementation.
The original url is encrypted using SHA-1 to a 40 hex encrypted hash.
We slice this 40 hex hash into 5 equal parts of 8 hex each, which is converted into decimal which again is base62 encoded.
This splitting into 5 equal parts is done to make sure that our final base-62 encrypted string will have a length of ≤ 7, since the main target is to produce a shortened url.
This shortened url is then stored in database along with the original long url as a kind of a mapper, which will be used while redirection of the shortened url to the original url.
Now while storing the shortened url in database, we will first check if this shortened url exists or not. If it exists, then we will put some degree of randomness and will generate the shortened url again.
This retry count has been limited to 10 in our implementation, so as to not affect latency of the system a lot. Also as per our functional requirement, the expiry of the shortened url in database is 3 months.
One can run test/url-shorten.js file to see the working of shortener
Repeats in a run of 1000000 are 99 with repeat percentage of 0.009899999999999999.
Repeats in a run of 8500000 are 8416 with repeat percentage of 0.09901176470588235.
Repeats in a run of 10000000 are 11725 with repeat percentage of 0.11725.
https://swapnilsatpathycse24.medium.com/url-shortener-b5b231068e0
FAQs
A URL shortener using SHA1 encryption with no external api
We found that @swapnil-pando/url-shortening 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.