What are git hooks?
Git hooks are scripts that are triggered by certain actions in the software development process, like committing or pushing. By automatically pointing out issues in code, they allow reviewers not to waste time on mistakes that can be easily diagnosed by a machine.
There are client-side hooks, that execute locally on the developers’ workstation, and server-side hooks, that execute on the centralized version control system.
If you are interested to explore further git hooks, here is a curation of the most useful git hooks on GitHub.
As a general security principle, where feasible, data should remain safe even if it leaves the devices, systems, infrastructure or networks that are under organization control, or if these are compromised. Assuming a breach helps prevent lateral movement after a hacker gains initial access.
In their everyday life, developers handle a trove of sensitive information that hackers could leverage. They rely on hundreds of secrets like API keys, database connection strings, private keys, or certificates to interconnect payment systems, databases, CRMs, messaging and notification systems, internal services… Too often, these secrets are hardcoded in source code or shared over Slack or emails. All these systems are not designed to store and share secrets, nor are internal wikis a good place to expose usernames and passwords.
Indeed, because of the very nature of software development, source code is made to be cloned on different workstations, deployed on multiple servers, distributed to customers, etc. In practice, you never know where your code is going to end up. If it contains secrets, it takes just one of these places to be compromised for all the secrets to be compromised as well. Same reasoning holds for all developers having access to source code: it takes one compromised developer account to compromise all the secrets they have access to.
On top of that, API keys and other secrets that are used to programmatically authenticate or authorize ourselves are unlike traditional usernames and passwords: because they are made to be programmatically used, they aren’t further secured by MFA (most of the time).
Here are some general principles about fitting security in the software development process:
Secret detection has one extremely important peculiarity though: unlike cryptography weaknesses or SQL injection vulnerabilities that only express themselves the moment the code is deployed, any secret reaching version control system must be considered compromised thus requiring immediate attention, even if the code is not ready to be deployed yet.
This implies that implementing secrets detection is not only about scanning the most actual version of your master branch before deployment. It is also about scanning through every single commit of your git history, covering every branch, even development ones.
GitGuardian comes in the form of a dashboard centralizing policy breaks across your organization’s repositories.
It is natively integrated with your Version Control System in a post-receive fashion. When integrating a repository into your monitored perimeter, secret detection is enforced on every branch, without making any distinction between development and master branches.
At every push, GitGuardian not only scans actual source code as would be the case if we were looking at other security vulnerabilities such as vulnerable dependencies, but on top of that, we also go through every incremental change that was made since the last push.
We also encourage you to run security checks early and often by using our API. Our API allows you to use our secrets detection as a service in pre-commits, pre-push, or in your CI (although CI builds aren’t typically enforced on all branches to scan every incremental change that was made). This would complement native integration with your Version Control System.
At GitGuardian, we are always keen to share the technical details of what we do, and all the subtleties we found in our journey to automate secrets detection. We are committed to doing so, even if it is not directly related to the objectives that we are trying to reach as a company.
We do this in the spirit of Open Source, knowing that sharing technical details allows us to get more feedback from developers and Application Security professionals around the world, and ultimately create more value.
Try GitGuardian, sign up with GitHub
This article was first published on GitGuardian's blog.