A Comprehensive Guide to Bitbucket Security Best Practices

Graphic of the scanning app
Don't Be the Next Headline.
Download the free ebook and see proven strategies to prevent a data breach from real-world examples.

Bitbucket is one of the most popular tools among developers to be able to collaborate and share their projects among the team. While developer platforms are essential across countless teams, code repositories can be a prime target for hackers to attack regularly. 

Tools like Bitbucket can often get overlooked when it comes to security. The lack of proper security measures in Bitbucket can open up the risks for attackers to steal sensitive information and deploy malicious source code into your software. Ramifications of which can be both timely and costly to the software development pipeline for both the team and company.

In this guide we’ll cover the importance of Bitbucket in software development for both developer teams and companies. We’ll also explore security issues faced by using public and private collaborative tools like Bitbucket and the top 6 security recommended security practices for Bitbucket to implement to increase the integrity of the software development cycle within your developer teams.  

The Importance of Bitbucket in Software Development

The software development industry relies heavily on tools that streamline workflows and promote collaboration on projects. For countless development teams, tools like Bitbucket serve as a key component of their project pipeline and delivery.

Bitbucket can be used in many different ways and can vastly benefit the software development cycle for teams. For example, Bitbucket Server and Data Center promote source code control and collaboration across developer teams. This allows teams to provide developers with a centralized platform to track changes, restore to the previous stages or versions of code, and maintain multiple versions of their code seamlessly.

Bitbucket also supports teams by providing integration and collaboration with the following:

  • It integrates with other programs, such as Jira and Slack, for project management and communications. 
  • Developers can collaborate on projects in real-time to complete tasks such as reviewing code, managing pull requests, and providing direct feedback within the platform.
  • Supports code security by providing branch permissions and pull request approvals, to ensure that only authorized changes are made to the codebase.

Bitbucket is important in the software development cycle because it can support and foster effective collaboration for teams. Solutions like Bitbucket can also support an effective delivery of code for each team's sprint ensuring accuracy and security of the code.

Security Challenges with Using Bitbucket

Bitbucket, like any other web-based tool, is not immune to security vulnerabilities and challenges. Recognizing these challenges is crucial for users of these tools in order to protect their repositories and maintain the integrity of their projects. It can also help developers safeguard their code and intellectual property more effectively.

The majority of Bitbucket's security vulnerabilities and Bitbucket security mistakes can broadly be categorized into three areas - project repository integrity, user access security, and third-party integrations.

Protection of both public and private repositories is crucial to prevent intrusion by unauthorized users to be able to access and manipulate the code causing disruptions to projects. Public repositories and users often need extra layers of user access controls, but private ones should implement strong security controls as well.

As disclosed in CVE-2022-43781, certain Bitbucket Server and Data Center versions have a critical vulnerability that could allow for a command injection attack. It can create an opportunity for an attacker to execute user privilege escalation once they have gained unauthorized access to the repository. If threat actors have control a user account, this can allow them to execute arbitrary code on the system. Exploits like these can not only disrupt or even destroy projects, but it can also lead to the distribution of compromised software.

Integrations with other software programs can also create challenges for developer teams that use Bitbucket for their delivery pipeline. Bitbucket integrations with various third-party services and tools can be highly beneficial, but it can also pose a unique set of risks. Integrations can be exploited to gain unauthorized access to repositories or sensitive data. It can then be used or sold to further exploit other users of the platform.

Top 6 Bitbucket Security Best Practices

In order to minimize the risks within your Bitbucket environment, there are several security best practices that teams can implement. These best practices can help safeguard against attacks and unauthorized repository access to your Bitbucket. 

Keep Bitbucket Updated & Regularly Patched

Inadequate patching and not performing regular software updates can open your Bitbucket up to greater security risks. Keeping your environment updated and patched with the latest security improvements can ensure your developer teams can execute their workflows successfully. Regular patching of security vulnerabilities can also help mitigate any technical gaps for the team. Users can also subscribe to notifications on any security updates or vulnerability released directly to ensure they have the latest features and patches available for Bitbucket. 

Enact Strong Access Controls

Nowadays cybercriminals are able to find ways to exploit a company's access controls in order to gain access to their systems and data successfully. This is why enacting strong user and contributor access controls is crucial to protecting the integrity of the data stored in Bitbucket repositories.

One of the most fundamental steps in securing your Bitbucket account is enabling either multiple factors or two factor authentication controls. By requiring an additional step to your access verification process, it adds an extra authorization layer of security settings to your user Bitbucket accounts. This would ensure that in the event a user account is compromised, the hackers would still only have limited access to it since they would need the registered device to fully verify the user and gain entry.

Teams can also employ the use of SSH keys as they are safer than passwords for user accessibility. SSH keys create a secure connection between the user's device and Bitbucket. The public key can be shared with Bitbucket while the private key remains securely on the user's device. Someone who attempts to connect to Bitbucket without the private key will limit access to your repositories.

Remove Sensitive Data in Your Bitbucket Repository

Developers often hardcode sensitive data such as credentials and API keys. The sensitive info then winds up into the codebase by mistake (or because they don't know any better).

The risk is that this practice poses significant security issues, as it increases the probability of an attacker within the network able to access sensitive data stored in the code repository.

Attackers will often scan repositories they have infiltrated for leaked data, including credentials stored improperly in the code, and then use this information to gain unauthorized repository access.

Even well trained developers make the mistake of adding sensitive information to code.

That's why it's crucial to block sensitive information from ever entering your codebase and scanning existing code for past mistakes (see Security for Bitbucket).

In summary, remove sensitive data and properly store your secrets in Bitbucket.

Review and Audit Activity Logs in the Bitbucket Supply Chain

Third party integrations can many times be the greatest risk to organizations. In addition to implementing security controls for all users and contributors access, monitoring activity logs in your Bitbucket environment can be key to mitigate any suspicious user activity. This can include the user pathways within your environment via their IP and login activity.

Adopting a verify then trust framework for the account access and user activity for all of those in your environment can increase your Bitbucket security. It can also be a great security best practice to enlist in enabling IP whitelisting. By doing this you ensure that only users accessing Bitbucket from approved IP addresses can interact with your account's private content. 

Implement Bitbucket Branch Permissions and Code Reviews

Secure coding requires teams to ensure the integrity of the code they produce. For companies using Bitbucket as their source control system, implementing branch permissions and code reviews can be a strategic necessity. It allows for developer teams to enhance security, streamline workflows, and provide project quality control. 

Implementing Bitbucket branch permissions is simple to do. This process is only available to users who are a user listed as a project or system administrator permission to set or modify branch permissions in Bitbucket. Here is the step-by-step Bitbucket process to do so as per Atlassian:

  1. Navigate to a repository in a project you want to set permissions on
  2. Choose the settings tab and then navigate to branch permissions 
  3. Click on Add permissions
  4. Select either Branch name, Branch pattern, or Branching model in the dropdown
  5. Choose the type of actions you want to prevent
  6. Click on the Create button to finish

In addition to branch permissions, teams can establish a code review policy that defines what a good code review looks like for the team. This includes review criteria, expected turnaround times, and the extent of the review process. They can also use pull requests for reviews in Bitbucket to facilitate code reviews which can then be reviewed by leadership and peers. These pull requests can act as a second review to ensure code integrity before the full commit. 

Invest in Bitbucket Automated Security Solutions

Screenshot of Security for Bitbucket
Clicking "Scan All" will find sensitive info in the codebase

Investing in automated Bitbucket security solutions can help countless teams further secure their Bitbucket repositories. Employing solutions such as a Bitbucket secret-scanning solution offered by Soteri can ensure that your repositories are secure from data leaks and block dangerous code commits.

Automated tools, like Security for Bitbucket from Soteri can scan for sensitive info stored in your code and block any commits that contain secret data. This proactive approach to security safeguards your code and significantly reduces the risk of security breaches. It can also support adhering to regulatory compliance and industry standards by understanding where your security settings and gaps may lie in the Bitbucket environment for your team.

Enhancing Bitbucket Security with Soteri

Bitbucket supports countless dev teams to maintain their coding cycles successfully. In addition to a fortified security posture, source code can still be leaked if not properly secured in the Bitbucket repository. This is why it's important to use security tools like those offered by Soteri as they automatically scan Bitbucket for any information leaks.

This can then take away some of the overhead of security teams but maintain a high-quality and proactive security posture.

Book a demo with us today to learn how Soteri supports better securing your Bitbucket repositories.