Need help?
<- Back

Comments (72)

  • bob1029
    I don't understand the need for this level of engineering. It appears we are going for an opaque bearer token here. The checksum is pointless because an entire 512 bit token still fits in an x86 cache line. Comparing the whole sequence won't show up in any profiler session you will ever care about.If you want aspects of the token to be inspectable by intermediaries, then you want json web tokens or a similar technology. You do not want to conflate these ideas. JWTs would solve the stated database concern. All you need to store in a JWT scheme are the private/public keys. Explicit tracking of the session is not required.
  • weitendorf
    Hey OP, sorry for the negativity, I think most of these commenters right now are pretty off-base. My company is building a lot of API infrastructure and I thought this was a great write up!
  • randomint64
    While it's true that API keys are basically prefix + base32Encode(ID + secret), you will want a few more things to make secure API keys: at least versioning and hashing metadata to avoid confused deputy attacks.Here is a detailed write-up on how to implement production API keys: https://kerkour.com/api-keys
  • ramchip
    The purpose of the checksum is to help secret scanners avoid false positives, not to optimize the (extremely rare) case where an API key has a typo
  • Savageman
    Side note: the slug prefix is not primarily intended for the end-user / developer to figure out which kind of key it is, but for security scanners to detect when they are committed to code / leaked and invalidate them.
  • calrain
    I don't like giving away any information what-so-ever in an API key, and would lean towards a UUIDv7 string, just trying to avoid collisions.Even the random hex with checksum component seems overkill to me, either the API key is correct or it isn't.
  • vjay15
    Hello everyone this is my third blog, I am still a junior learning stuff ^_^
  • tjarjoura
    I've always been interested in the technical distinction between an API "key" and an API "token". And the terminology of "key" used to confuse me, because I associated that with cryptography, and I thought an API key would be used to sign or encrypt something. But it seems that in many cases it's basically just a long, random password.
  • petterroea
    A bit over-engineered, but it was fun to read about observations on industry standard API keys. I agree it would be nice with more discussion around API keys and qualities one would want from them.
  • pdhborges
    I don't even understand what approach 3 is doing. They ended up hashing the random part of the API key with an hash function that produces a small hash and stored that in the metashard server is that it?
  • tlonny
    Presumably because API keys are n bytes of random data vs. a shitty user-generated password we don’t have to bother using a salt + can use something cheap to compute like SHA256 vs. a multi-round bcrypt-like?
  • anon
    undefined
  • matja
    What if the "slug" was a prefix for the API key revocation URL, so the API key was actually a valid URL that revoked itself if fetched/clicked? :)
  • dhruv3006
    Hey - this was a great blog ! I liked how you used the birthday paradox here.PS : I too am working on a APIs.Take a look here : https://voiden.md/
  • amelius
    It's a bit confusing that the "Random hex" example contains characters such as "q" and "p".
  • hk__2
    > I didn't proceed with this approach since I don't want the API keys to have any info regarding the account, but hey it is all just a matter of preference and opinion.Well I would have done that and saved half the blog post.
  • usernametaken29
    I know sometimes people just like to try things out, but for the love of god do not implement encryption related functionality yourself. Use JWT tokens and OpenSSL or another established library to sign them. This problem is solved. Not essentially solved, solved. Creating your own API key system has a high likelihood of fucking things up for good!
  • sneak
    This is a very good example of premature optimization.
  • SyndicateLinks
    [dead]
  • MORPHOICES
    [dead]
  • Serhii-Set
    [dead]
  • adaptit
    [dead]
  • grugdev42
    Everything about this is over engineered. Just KISS.
  • codingjoe
    Is this running in a production environment yet? If so, do you have an email address to disclose a vulnerability?