
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
github.com/mralanlee/url-shortener-api
URL Shortener written in Go. Really fun project since I generally build APIs in Node.js and primarily use NoSQL databases. This task took me about ~5.5 hours.
$ docker-compose up --build
Dependencies from the Docker image are MySQL and Golang.
I didn't get a chance to write all the tests that I could as I wanted to stay as close to the 4 hour mark. I didn't get to approach it in a more idomatic way. When I started working on it, I realized I ended up setting it up as more of an end-to-end test instead of actual unit tests.
$ docker-compose -f docker-compose.test.yml up --build -d
$ go test -v
I also approached the tests in a Table Test way, so it would be more DRY.
There is a concept of the slug, where that's the randomized token that unlocks or redirects you to the original source.
POST /api/shorten Shorten's URLs
curl -X "POST" "http://localhost:3000/api/shorten" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"url": "http://localhost:3000/asdfdsf"
}'
GET /api/stats?url= Get Stats
curl "http://localhost:3000/api/stats?id={slug}"
GET /{slug} Redirect
curl "http://localhost:3000/{slug}"
http://localhost/${slug}
.)
- Is Unique; If a long url is added twice it should result in two different short urls.
- Not easily discoverable; incrementing an already existing short url should have a low probability of finding a working short url.
All the validation should occur at the handler level, that way the database doesn't get bogged down trying to figure out whether a URL is valid or not.
POST
request respond with 405
500
url
key and/or value is not a url
respond with bad requesttrigger
to increment on read but I don't think that's possible.url.ParseRequestURI
. (Source)try/catch
in the majority of my work experience.If I had more time, I would have focused on the following items:
I tried my best to stay as close to a 4 hour time requirement.
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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.