Story Time: API Key in Repo

In my previous article, Best Lessons Learned to Date, I brought up the importance of keeping your secrets (#7) and a time that I published one of my API keys to GitHub. This is that story.

The Story

In Fall 2022, I was working on a project for CSC 4610 - Advanced Topics in Web Development that I called PokéTCG Card Manager. Because part of the premise was displaying cards and information about them, I decided it would be best to use an API instead of storing all of that information myself. Anyway... as I was implementing some of the basic API interactions, I stupidly put my API key directly into one of the views (in this commit) thus violating a few best practices in Laravel that I've since learned—I shouldn't have been doing an API call there to begin with—and later (in this commit) moved my new key to an env.

Moral of the Story

First, always ensure that you have an environment file (i.e.: .env) set up to store all of your sensitive information. You should never be putting information like API keys or login credentials in any other file. Here is a good Medium article I found talking more about .env files.

Second, always ensure that you have set up your version control systems to ignore the environment file (i.e.: putting .env in your .gitignore file). This will prevent the version control system from publishing that file.

Third, I was lucky. I was lucky to make this mistake and learn this lesson with a key that was fairly inconsequential when API key insecurity is estimated to costs organizations between $41 and $75 billion annually (source). But at least that also means we're definitely not alone in making this mistakes.

Conclusion

Thanks for reading this edition, and I apologize if it's a little short or sloppy. As I explained in this post, the article I was planning on publishing this week apparently didn't save so I had to write this one relatively last minute.

Have you ever pushed a secret to the internet? I'd love to hear your stories too!

Jacob Knox

Future Software Dev. | B.S. in CS & Math

1 年

Here is a good example of a more severe instance of this that came across my email the other day thanks to TLDR. It highlights the potential repercussions of such a leak. https://redhuntlabs.com/blog/mercedes-benz-source-code-at-risk-github-token-mishap-sparks-major-security-concerns/?utm_source=tldrinfosec

回复

要查看或添加评论,请登录

Jacob Knox的更多文章

  • Having Structure and Direction

    Having Structure and Direction

    Something I wish I knew from the very start is the importance of having structure and direction in learning and in…

  • Your Local Environment

    Your Local Environment

    Confused by the title? Don’t worry, this isn’t some tangent about the importance of conservationist efforts to your…

  • Good Coding Practices

    Good Coding Practices

    In this edition, I’d like to go into significantly more detail about good coding practices, which was #2 in my first…

  • Best Lessons Learned to Date

    Best Lessons Learned to Date

    When I first started to code, I was naive and simply hungry to consume as much (mostly) useless knowledge about as many…

  • Welcome to Oops2Ops: Coding Stories!

    Welcome to Oops2Ops: Coding Stories!

    First, thank you for taking the time to look into what the heck this new newsletter I'm starting is. I appreciate that…

社区洞察

其他会员也浏览了