Skip to content
Info disclosure Write-up Beginner

NotLegit: Azure App Service vulnerability exposed hundreds of source code repositories

Azure App Service exposed hundreds of source code repositories, allowing attackers to retrieve source code and potentially secrets.

Shir Tamari Follow

Published on wiz.io

Bounty$7,500 View original

The Wiz Research Team detected an insecure default behavior in the Azure App Service that exposed the source code of customer applications written in PHP, Python, Ruby, or Node, that were deployed using “Local Git”. The vulnerability, which we dubbed as “NotLegit”, has existed since September 2017 and has probably…

Shir Tamari, on wiz.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

The Azure App Service (also called Azure Web Apps) is a cloud platform for hosting websites and web applications. You pick a supported language and operating system, then deploy source code or build artefacts to an Azure-managed server over FTP, SSH, or by pulling from a Git service such as GitHub or a private Git repository. Once deployed, the application is reachable by anyone on the internet under its *.azurewebsites.net domain.

One of the deployment methods is "Local Git". With Local Git, Azure initialises a Git repository inside the App Service container, and you push your code straight to the server. The Wiz Research Team found that this repository was created inside the publicly accessible web root, /home/site/wwwroot, so the .git directory could be fetched over HTTP. They named the issue NotLegit. It had existed since September 2017 and, in the team's assessment, had probably been exploited in the wild.

Setup

The relevant preconditions are deployment choices:

  1. The application is written in PHP, Python, Ruby or Node.
  2. It was deployed with Local Git on a clean default application, or deployed with any Git source after a file had been created or modified in the container (for example via FTP, Web Deploy or SSH).
  3. IIS-based applications (C# or ASP.NET) are not affected.

To measure real-world exposure, the team deployed a vulnerable App Service application, linked it to an unused domain, and waited to see whether anyone would request the .git files.

Finding it

The starting point is a well-known rule: when you deploy a Git repository to a web server or storage bucket, the .git folder must not be uploaded, because it contains the source code, developers' email addresses and other sensitive data. In the Local Git case, the repository was created inside the public directory, which Microsoft knew about. As a protection, Microsoft placed a web.config file inside the .git folder in the public directory to restrict public access.

The problem is that only Microsoft's IIS web server processes web.config files. C# and ASP.NET applications run behind IIS, so for them the mitigation works. PHP, Ruby, Python and Node applications are served by other web servers (Apache, Nginx, Flask and so on), which ignore web.config entirely. For those applications the mitigation had no effect, and the whole .git directory was reachable. All an attacker had to do was fetch the /.git directory from the target and retrieve its source code.

There is a detail worth recording: Microsoft's web.config contained a typo, an unclosed configuration tag, which made the file unparseable by IIS. The error it raised ended up blocking access to the entire directory, so the file served its purpose anyway.

Microsoft later found a second route to exposure. If a file was created or modified in the App Service container (via FTP, Web Deploy or SSH) before any Git deployment, the service enters an "inplace deployment" state. That state forces any later Git deployment to be initialised inside the publicly accessible directory. The Kudu wiki page "Deploying inplace and without repository" describes this behaviour.

Exploitation

Step 1: identify an affected application

The affected set is defined by deployment history rather than by any visible banner:

  • PHP, Node, Ruby and Python applications deployed with Local Git on a clean default application since September 2017.
  • PHP, Node, Ruby and Python applications deployed from September 2017 onward using any Git source, after a file was created or modified in the application container.

IIS-based applications are excluded.

Step 2: fetch the Git directory

The exploitation itself is a single retrieval. The attacker requests the /.git directory from the target application and recovers the source code from it. The report describes the action as fetching the /.git directory; it does not print a specific request line, so no exact request is reproduced here.

Step 3: confirm exploitation happens in the wild

The team deployed a vulnerable application on an unused domain and watched. Within four days of deployment, multiple requests for the .git folder arrived from unknown actors. That is the practical confirmation that scanning for this path is continuous and automated.

Root cause

The design mistake is placing the Git repository inside the document root. Local Git created the repository in /home/site/wwwroot, a directory served to the public, instead of somewhere outside the web root. The only defence was a web.config access restriction, which is an IIS-specific mechanism. Any runtime served by Apache, Nginx, Flask or a comparable server simply ignored it, so the restriction did not exist for PHP, Ruby, Python and Node applications. The second contributing behaviour is the "inplace deployment" state: a prior file creation or modification in the container forces later Git deployments into the public directory, extending exposure to users of other Git deployment tools.

Impact

Anyone on the internet could retrieve the source code of an affected application. Leaked source can itself contain secrets such as passwords and access tokens, and it is commonly used for further attacks: gathering intelligence on the R&D division, mapping internal infrastructure, and finding software vulnerabilities, which is much easier with the code in hand. The affected population is every PHP, Node, Ruby and Python application matching the deployment conditions above, from September 2017 onward.

The distinctive point is that the cloud users did nothing wrong. They did not accidentally expose their Git folder; the Azure service did. Because the flaw was in the platform, exposure happened at scale, without customers knowing and without them having any control over it. Accidental .git exposure through user error has hit large organisations before, including the United Nations and a number of Indian government sites, but NotLegit is a platform-side exposure.

Fix

Microsoft investigated the issue with MSRC and the Azure App Service team, found the cause, and applied a fix covering most affected customers. The fix for PHP applications was deployed on 17 November 2021. From 7 December 2021 Microsoft began emailing customers who were still potentially exposed, with alerts continuing to 15 December 2021; those customers had to take user actions themselves to protect their applications. The report does not describe the technical content of the fix.

Variants to test

  1. Direct .git retrieval on other PaaS runtimes. Request the /.git directory on applications built with PHP, Node, Ruby or Python on any platform that offers a Git-based deployment. A positive result is that the /.git directory can be fetched and the source code retrieved from it.
  2. Server-specific access rules. Where a platform ships an IIS web.config access restriction, test the same path under a runtime served by a different web server. A positive result is that the path is reachable on the runtime whose server does not read that file.
  3. Deployment-state transitions. Create or modify a file in the application container before performing a Git deployment, then check where the repository lands. A positive result is a repository created inside the publicly served directory.
  4. Passive confirmation. Deploy a test application on an unused domain and monitor requests to the .git path. Requests from unknown sources within days indicate that strangers are actively looking for the .git path.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

Microsoft runs a service called Azure App Service, where people put their websites and web apps on Microsoft's computers so anyone on the internet can visit them. One of the ways to upload your code to that service is called "Local Git". The Wiz Research Team found that when you used Local Git, the service put a copy of your code in a folder that anyone on the internet could read. That copy is called the .git folder, and it holds your source code and the email addresses of the people who wrote it.

The flaw had existed since September 2017 and, in the team's assessment, had probably been exploited in the wild. Wiz reported it to Microsoft on 7 October 2021, and by the time of writing it had been mitigated. Small groups of customers were still potentially exposed and had to take certain actions themselves, as described in several email alerts Microsoft issued between 7 and 15 December 2021. Microsoft granted Wiz a $7,500 bounty for the finding, which the team planned to donate.

This article walks through the whole story from the beginning: what the service is, what the deployment method is, why the folder ended up public, who was affected, how the team confirmed that strangers were actually looking for it, and what Microsoft did about it.

Recapping the basics

What is the Azure App Service?

Azure App Service (also called Azure Web Apps) is a cloud platform for hosting websites and web applications. "Cloud" here means computers run by someone else that you reach over the internet. Instead of buying a machine and keeping it in a room, you let Microsoft run it for you.

The service is easy to use, and therefore very popular. The flow is:

  1. You select the supported programming language and operating system.
  2. You deploy your application source code or artefacts on an Azure-managed server, using FTP, SSH, or by pulling the source code from a Git service such as GitHub or a private Git repository.
  3. After deployment, the application is accessible for anyone on the internet under their *.azurewebsites.net domain.

A few of those words need unpacking for a first-time reader:

  • Source code is the text a programmer writes: the instructions that make the website work.
  • Artefacts are the packaged result of building that code, ready to run.
  • FTP (File Transfer Protocol) is an old, simple way of copying files from one computer to another, a bit like dragging files into a shared folder.
  • SSH (Secure Shell) is a way to log in to another computer's command line and run commands on it.
  • Git is a version-control system: a tool that records every change to a set of files, so you can see history and roll back. A Git repository is the folder Git keeps, containing your files plus that history.
  • A domain is the human-readable name of a website, such as example.com. *.azurewebsites.net means every name ending in azurewebsites.net, one per customer app.

What is "Local Git"?

Azure supports multiple methods to deploy source code and artefacts to the App Service, one of which is using "Local Git". With Local Git, you initiate a local Git repository within the Azure App Service container that enables you to push your code straight to the server.

In everyday terms: normally you write code on your own laptop and then copy it up. With Local Git, Azure creates a Git repository for you on its side, inside the space reserved for your app (the container, meaning the isolated slice of the server your app lives in). You then "push", which means sending your commits, the recorded changes, from your machine to that repository. It is like a shared notebook that lives at the destination, and you post your pages into it.

Figure 1: Supported Git deployment sources in Azure App Service

The security flaw: your local Git repository was publicly accessible

As a best practice, when you deploy Git repositories to web servers and storage buckets, it is always important to ensure that the .git folder is not uploaded as well. Why? Because the .git folder contains the source code, developers' emails, and other sensitive data.

Think of the .git folder as the notebook's carbon copies: even if you only meant to publish the final page, the carbon copies underneath contain every draft, every author's name, and every note in the margin. If a visitor can reach the carbon copies, they can read everything.

However, when the Local Git deployment method was used to deploy to the Azure App Service, the Git repository was created within the publicly accessible directory (/home/site/wwwroot) that anyone could access. A directory is just a folder; "publicly accessible" means the web server will hand out files from it to anyone who asks over HTTP, the protocol your browser uses.

This was a known quirk to Microsoft. To protect your files, Microsoft added a web.config file to the .git folder within the public directory that restricted public access. A web.config file is a settings file that Microsoft's web server, IIS (Internet Information Services), reads to decide how to behave, including who may see which folder.

However, only Microsoft's IIS web server handles web.config files. If you use C# or ASP.NET, the application is deployed with IIS and this mitigation is perfectly fine. C# and ASP.NET are Microsoft's own programming language and web framework, so they naturally run on Microsoft's own web server.

But what happens when you use PHP, Ruby, Python or Node? These programming languages are deployed with different web servers (Apache, Nginx, Flask, etc.), which do not handle web.config files, leaving them unimpacted by the mitigation and therefore completely vulnerable. In plain terms: the lock was fitted, but only one of the doors has a keyhole for it. Apache, Nginx and Flask are other web server programs, each with its own way of being configured; none of them reads web.config.

Basically, all a malicious actor had to do was to fetch the /.git directory from the target application, and retrieve its source code. "Fetch" here means a normal web request, the same kind your browser makes when you type an address. No password, no trick, no special tool: just ask for the folder and read what comes back.

Fun fact: Microsoft's web.config file had a typo (the configuration tag wasn't closed properly) that made the file unparseable by IIS. Luckily, the error raised by the typo ended up blocking access to the entire directory, so you could say that web.config served its purpose after all.

A tag here is a piece of markup in a settings file, opened and closed like brackets. Leaving one unclosed makes the file invalid, and IIS refused to read it. The refusal happened to lock the whole directory, which is why the typo accidentally helped.

Figure 2: The typo in web.config

Later on, Microsoft discovered that users who used other Git deployment tools could also be exposed: if a file was created or modified in the Azure App Service container (using FTP, Web Deploy or SSH) before any Git deployment, then the service enters an "inplace deployment" state. This state forces any future Git deployment to be initiated within the publicly accessible directory. For more details, refer to Deploying inplace and without repository.

In everyday terms: if you had already put something in the room before the movers arrived, the movers decided to unpack everything in that same room, even if they would normally have used a back room. Web Deploy is another Microsoft tool for copying files to a server. Kudu is the behind-the-scenes engine Azure uses to run deployments.

NotLegit Vulnerability

Who's affected?

The affected set is defined by deployment history rather than by any visible banner:

  • All PHP, Node, Ruby and Python applications that were deployed using "Local Git" on a clean default application in Azure App Service since September 2017.
  • All PHP, Node, Ruby and Python applications that were deployed in Azure App Service from September 2017 onward using any Git source, after a file was created or modified in the application container.

The only applications that were not impacted by this security flaw are IIS-based applications.

Microsoft emailed different notifications to all impacted users based on their configuration between 7 and 15 December 2021.

Figure 3: One of the emails Microsoft sent to affected customers

Exploiting .git in general

An exposed .git folder is a common security issue that users make without even realising it. Malicious actors are continuously scanning the internet for exposed Git folders from which they can collect secrets and intellectual property. "Scanning" means automated programs asking millions of addresses the same question, over and over, looking for the ones that answer.

Besides the possibility that the source contains secrets like passwords and access tokens, leaked source code is often used for further sophisticated attacks: gathering intel on the R&D division, learning the internal infrastructure, and finding software vulnerabilities. Finding vulnerabilities in software is much easier when the source code is available. An access token is a short string that acts like a temporary key, letting whoever holds it use a service without typing a password. Intellectual property means the valuable ideas and code a company owns.

Accidentally exposing the Git folder through user error is a security issue that can impact even large organisations. Both the United Nations and a number of Indian government sites have been exposed this way in the past, for example. What stands out with NotLegit is that here cloud users did nothing wrong. They did not mistakenly expose their Git folder: the Azure service did. Because the security issue was in an Azure service, cloud users were exposed on a big scale, and without them knowing or having any control over it.

That distinction matters. In the usual case, someone forgets to lock a door. Here, the landlord installed the door in the wrong wall and told the tenant it was locked.

Exploited in the wild

To assess the chance of exposure with the issue we found, we deployed a vulnerable Azure App Service application, linked it to an unused domain, and waited patiently to see if anyone tried to reach the .git files. Within 4 days of deploying, we were not surprised to see multiple requests for the .git folder from unknown actors.

This is a test application on an unused domain, set up to observe who comes knocking.

Figure 4: Multiple requests from unknown actors to our testing .git folder

As this exploitation method is extremely easy, common, and is actively being exploited, we encourage all affected users to review their application's source code and evaluate the potential risk:

  • Users who deployed code via FTP or Web Deploy or Bash/SSH which resulted in files getting initialised in the web app before any git deployment.
  • Users who enabled LocalGit on the web app.
  • Users who used a subsequent Git clone/push sequence to publish updates.

A clone is copying a Git repository down to your machine; a push is sending your changes back up. Bash is a common command-line shell, the program where you type commands.

Wiz's responsible disclosure and Microsoft's response

After disclosing the NotLegit vulnerability to Microsoft, Microsoft understood the severity of this issue and took all the necessary steps in order to investigate and mitigate it. MSRC and the Azure App Service team conducted a deep investigation and found the cause of the issue, applied a fix that covers most affected customers, and emailed notifications to warn all customers who were still exposed and await user action (hopefully already taken after the customer notification on 7 December).

Responsible disclosure is the practice of telling the vendor privately first and giving them time to fix the problem before you talk about it publicly. MSRC is the Microsoft Security Response Center, the team that handles reports like this one. Mitigate means reduce the harm, which is not always the same as removing the cause completely.

Microsoft also granted Wiz a $7,500 bounty for this finding, which the team planned to donate. A bug bounty is a reward a company pays to someone who reports a security problem to it.

Disclosure timeline

  • 12 September 2021: Wiz Research Team first noticed the insecure behaviour.
  • 7 October 2021: Issue reported to Microsoft.
  • 8 October 2021: Report received by Microsoft.
  • 14 October 2021: Microsoft asked for a conference call to discuss and triage the issue.
  • 19 October 2021: Conference call with MSRC and the Azure App Services team.
  • 22 October 2021: Report acknowledged and Wiz was awarded a $7,500 bounty.
  • 17 November 2021: The fix for PHP applications was deployed.
  • 7 December 2021: Microsoft started notifying vulnerable customers via email.

Triage is the first pass where a vendor decides how serious a report is and who should look at it.

Root cause

The design mistake is placing the Git repository inside the document root. Local Git created the repository in /home/site/wwwroot, a directory served to the public, instead of somewhere outside the web root. The document root (or web root) is the folder a web server is allowed to serve files from; anything inside it can be requested by a visitor, anything outside it cannot.

The only defence was a web.config access restriction, which is an IIS-specific mechanism. Any runtime served by Apache, Nginx, Flask or a comparable server simply ignored it, so the restriction did not exist for PHP, Ruby, Python and Node applications. A runtime is the combination of language and server that actually executes your app.

The second contributing behaviour is the "inplace deployment" state: a prior file creation or modification in the container forces later Git deployments into the public directory, extending exposure to users of other Git deployment tools.

Impact

Anyone on the internet could retrieve the source code of an affected application. Leaked source can itself contain secrets such as passwords and access tokens, and it is commonly used for further attacks: gathering intelligence on the R&D division, mapping internal infrastructure, and finding software vulnerabilities, which is much easier with the code in hand. The affected population is every PHP, Node, Ruby and Python application matching the deployment conditions above, from September 2017 onward.

The distinctive point is that the cloud users did nothing wrong. They did not accidentally expose their Git folder; the Azure service did. Because the flaw was in the platform, exposure happened at scale, without customers knowing and without them having any control over it. Accidental .git exposure through user error has hit large organisations before, including the United Nations and a number of Indian government sites, but NotLegit is a platform-side exposure.

Fix

Microsoft investigated the issue with MSRC and the Azure App Service team, found the cause, and applied a fix covering most affected customers. The fix for PHP applications was deployed on 17 November 2021. From 7 December 2021 Microsoft began emailing customers who were still potentially exposed, with alerts continuing to 15 December 2021; those customers had to take user actions themselves to protect their applications. The report does not describe the technical content of the fix.

Variants to test

These are the general lessons a security tester takes away, written so you can follow the reasoning even without a lab:

  1. Direct .git retrieval on other PaaS runtimes. Request the /.git directory on applications built with PHP, Node, Ruby or Python on any platform that offers a Git-based deployment. A positive result is that the /.git directory can be fetched and the source code retrieved from it. PaaS means Platform as a Service: the provider runs the servers, you only supply the app. HEAD is a small file inside a Git repository that records which version you are currently on.
  2. Server-specific access rules. Where a platform ships an IIS web.config access restriction, test the same path under a runtime served by a different web server. A positive result is that the path is reachable on the runtime whose server does not read that file. .htaccess is Apache's equivalent of web.config.
  3. Deployment-state transitions. Create or modify a file in the application container before performing a Git deployment, then check where the repository lands. A positive result is a repository created inside the publicly served directory.
  4. Passive confirmation. Deploy a test application on an unused domain and monitor requests to the .git path. Requests from unknown sources within days indicate that strangers are actively looking for the .git path.

About the team

Dealing with the need to know every service in depth is hard. So far, in 2021, Azure alone announced 402 new products and features, let alone what has been announced by AWS and Google Cloud. All told, it is nearly impossible for the average user to keep up. Wiz's research team, a group of cybersecurity veterans who have been in this space for over 10 years, works around the clock to identify potential security issues with cloud service provider services and help customers identify and address them. Sometimes, they find vulnerabilities in the platform itself. In 2021 alone, they helped AWS, Azure and Google Cloud fix 14 security vulnerabilities across multiple services.

AWS (Amazon Web Services) and Google Cloud are Microsoft Azure's two main competitors in cloud computing. CSP here means cloud service provider.

Special thanks to Sebastian Cornejo (@CuriositySec) who helped gather azurewebsites.net subdomains for this research. A subdomain is a name that sits under a larger domain, such as myapp.azurewebsites.net.

Glossary

  • Access token: a short string that acts like a temporary key, letting whoever holds it use a service without typing a password.
  • Apache: a widely used web server program that serves files and runs web apps.
  • Artefact: the packaged, ready-to-run result of building source code.
  • ASP.NET: Microsoft's framework for building web applications, which runs on IIS.
  • AWS: Amazon Web Services, a cloud computing provider.
  • Azure App Service: Microsoft's cloud platform for hosting websites and web applications, also called Azure Web Apps.
  • Bash: a common command-line shell where you type commands.
  • Bug bounty: a reward a company pays to someone who reports a security problem to it.
  • C#: Microsoft's programming language, commonly used with ASP.NET.
  • Clone: copying a Git repository from a server down to your own machine.
  • Container: the isolated slice of a server in which one application runs.
  • CSP: cloud service provider, a company that rents out computing services over the internet.
  • Directory: a folder.
  • Document root: the folder a web server is allowed to serve files from; anything inside it can be requested by a visitor.
  • Domain: the human-readable name of a website, such as example.com.
  • Flask: a web framework and server for Python applications.
  • FTP: File Transfer Protocol, an old, simple way of copying files between computers.
  • Git: a version-control system that records every change to a set of files.
  • Git repository: the folder Git keeps, containing your files plus their full history.
  • Google Cloud: Google's cloud computing provider.
  • HEAD: a small file inside a Git repository recording which version you are currently on.
  • Honeypot: a deliberately tempting but worthless target set up to observe who attacks it.
  • .htaccess: Apache's per-folder settings file, the rough equivalent of IIS's web.config.
  • HTTP: the protocol a browser uses to request pages and files from a web server.
  • IIS: Internet Information Services, Microsoft's web server, which reads web.config files.
  • Intellectual property: the valuable ideas and code a company owns.
  • Kudu: the engine Azure uses behind the scenes to run deployments.
  • Local Git: an Azure App Service deployment method that creates a Git repository inside the app's container so you can push code straight to the server.
  • Mitigate: reduce the harm caused by a problem, which is not always the same as removing its cause.
  • MSRC: the Microsoft Security Response Center, the team that handles security reports.
  • Nginx: a widely used web server program, an alternative to Apache.
  • Node: a runtime that runs JavaScript outside the browser, commonly used for web apps.
  • PaaS: Platform as a Service, where the provider runs the servers and you only supply the app.
  • PHP: a programming language widely used for websites.
  • Push: sending your recorded Git changes from your machine up to a repository.
  • Python: a popular general-purpose programming language, also used for web apps.
  • Responsible disclosure: telling a vendor privately about a security problem and giving them time to fix it before publishing.
  • Ruby: a programming language commonly used for web apps.
  • Runtime: the combination of language and server that actually executes your app.
  • Scanning: automated programs asking many addresses the same question repeatedly, looking for ones that answer.
  • Source code: the text a programmer writes, the instructions that make a website work.
  • SSH: Secure Shell, a way to log in to another computer's command line and run commands on it.
  • Subdomain: a name that sits under a larger domain, such as myapp.azurewebsites.net.
  • Tag: a piece of markup in a settings file, opened and closed like brackets.
  • Triage: a vendor's first pass at deciding how serious a report is and who should look at it.
  • Web Deploy: a Microsoft tool for copying files to a server.
  • web.config: an IIS settings file that controls, among other things, who may access which folder.
  • Web root: another name for the document root.

More by Shir Tamari

View all

6 more disclosed reports, best first.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.