A Simple Git Misstep That Could Open Doors for Hackers

Thinley Jigme
System Weakness
Published in
3 min readMay 6, 2024

--

Hi folks! 👋 Welcome to my second article, where we delve into a seemingly minor but potentially catastrophic oversight that developers might unknowingly commit.

In the realm of software development, even the smallest mistake can provide an opportune window for hackers.

Why GitHub Matters in This Context?

GitHub is vital for Continuous Integration and Continuous Deployment (CI/CD), enabling developers to collaborate efficiently, and automate development pipeline. While it simplifies development processes, it also demands vigilance. A lapse in attention could unintentionally open a backdoor for cybercriminals.

The Common Mistake: Careless Commit Messages

When you commit changes in your project, the commit message might seem like the least of your worries. However, words such as “key”, “env”, “credentials”, and similar terms can unintentionally hint at the presence of sensitive information in the commit.

Example: Consider using the command git log | grep key to look for commit message with word key. This can reveal commit messages that hint at the inclusion of sensitive data.

The Risk Beyond the Initial Commit

Suppose you realize that you’ve accidentally committed a file containing sensitive data (like .env or KEY.txt) and quickly remove it in a subsequent commit. While it might seem that you’ve handled the situation, the digital footprint of your mistake remains in the git history.

YES, you heard it right. Digital footprint!

The Enduring Trace in Git Logs

Git carefully records every action, and this history is accessible through various commands. For example, by using git log --help, you can explore tools and commands that interact with this history.

For now, we will particularly find the command relevant to us, i.e., one that filter.

Now, the command--diff-filter can filter the commit history based on the type of change.

To find deletions, use: git log --diff-filter=D --summary | grep KEY, where;

  • Dor d is used for filtering deletions,
  • --summary is used to print summary,

This command helps to identify the names of deleted files that matched sensitive keywords, potentially revealing the file ‘KEY.txt’.

How Hackers Exploit This Information

With the file name in hand, a hacker can further explore the git logs to find the exact commit hash where ‘KEY.txt’ was deleted.

Using git show <COMMIT_HASH>, they can view the contents of the file as it existed before deletion.

Conclusion

Understanding the nuances of git commands and their implications is crucial in safeguarding your repositories. Developers must be vigilant with every commit, mindful of the history they leave behind, and aware of how seemingly harmless details can be exploited. By adopting best practices for secure commits and maintaining a clean git history, we can provide defenses against potential cybersecurity threats.

Remember, in the digital world, every detail counts. Secure your code as diligently as you write it.

Keep learning. Until next time adios folks! ✌️

--

--

Backend Web Developer 🌐 | Cyber Security Enthusiast 💻 | Science Geek 🔭