Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.