[RFC] Avoid exposing unknown git repositories

Problem

The LLVM Security Group received a report that, in specific cases, an LLVM or Clang build could expose sensitive information from private repositories, i.e. username, password or private URL.

This happens because the build system uses the git repository information in order to set version information, e.g. clang --version.

git supports 4 transport protocols by default: git, ssh, http and https. ftp and ftps are also supported, but are deprecated [1].
git also provides a mechanism to bridge smart transport to an external command [2] and a way to add support for other transports out-of-tree [3].

When is sensitive data exposed?

For this to happen, all the following requirements must be satisfied:

  1. The build has to use a cloned git repository.
  2. The URL used for the remote must have sensitive information, e.g. https://user:password@private.url.com/myfork
  3. When calling cmake, the macros LLVM_FORCE_VC_REPOSITORY [4] and CLANG_REPOSITORY_STRING are not set.

Proposed solution

Instead of reusing data from git remote get-url, replace the code with the following pseudocode:

if remote-url == upstream-LLVM-Github:
  repository = "https://github.com/llvm/llvm-project"
endif

This would guarantee we would expose the main URL of the project on Github. Users can still clone from this URL.
If the build came from a different git repository, no information would be stored in the binary.

People downstream wanting to distribute binaries with a different string, would have to set LLVM_FORCE_VC_REPOSITORY [4:1].

An initial patch has been proposed here.


  1. Git - git-clone Documentation ↩︎

  2. Git - git-remote-ext Documentation ↩︎

  3. Git - gitremote-helpers Documentation ↩︎

  4. Building LLVM with CMake — LLVM 22.0.0git documentation ↩︎ ↩︎

1 Like

IMO, that we put the Git URL in the output by default is not something to be “fixed”. If someone wants to keep their git URL private while distributing binaries built from it, the knobs to allow them to do so are available. But, I believe the info of which fork a build came from is entirely reasonable to include by default in builds.

The username/password issue: I’d say that’s user error. You shouldn’t put passwords in the URL like that. Git supports many other ways to store passwords that don’t require putting your password in the URL, ~/.netrc, github’s “gh” integration, SSH_ASKPASS, etc.

7 Likes

I’m inclined to agree that it is user error.

However, that doesn’t mean we can’t error out if we detect something like this (similar to what we do for an invalid CMAKE_BUILD_TYPE). If we errored out when detecting an ampersand in the URL (at least for http(s) URLs), I think that would prevent binaries from getting distributed with passwords in the URL in the version page (at least unintentionally), while preserving this functionality for the other 99% of cases where it might provide benefit to those triaging issues.

3 Likes

Sure. I don’t object if we would just error out upon seeing something that has a password in it. That’s a less objectionable solution.

To avoid needing a full URL parser, perhaps it’s sufficient to just error on strings that match a regex of https?://[^/]*:[^/]*@.*.

For another data point, as a downstream, we definitely want the URL of our fork to end up in the binary (along with hash and branch).

2 Likes

For http and https, we also need to detect cases like http://user@example.com.
That means we need https?://[^/]*(:[^/]*)?@.*

Keep in mind this solution won’t detect mistakes in other transport protocols.

I can’t imagine reasonable regexes for the other protocols (git only seems to support four in total) would be too difficult to come up with?

1 Like

Plus ftp and ftps, which are deprecated.
If we try to hide other protocols too, we have to find a way to not hide ssh URLs like git@github.com:llvm/llvm-project.git

But I think the most difficult part is what I mentioned here:

If external commands/obscure protocols are a concern why not just check for “safe” https and ssh (potentially others if we are 100% they can’t have this problem) and require explicit opt-in for everything else? That should cover 99% of use cases.

I agree with you in restricting the protocols we protect to http, https and ssh.

In case my previous message was unclear: I was just pointing out corner cases to that proposal in order to guarantee that we know the limitations of the solution we take.

And in case what I was suggesting wasn’t clear either - if there is a concern that we’ll only protect these three protocols but can potentially have similar security issues in more obscure/custom/external ones, then we could just require an explicit opt-in for those corner cases (i.e. only allow urls-included-by-default for protocols we know how to “sanitize”).

Ehhh, IMO doesn’t really seem necessary to worry about username, without password. In such case, that also allows us to not care about validating anything for the ssh schemes, because git doesn’t support password for those, anyhow.

Again, I think it’s important to frame this as adding a guardrail to help users avoid their own error – not as fixing a bug, vulnerability, etc. Under that framing, there is no need for a validation to be comprehensive, and it’s fine for it to “fail open”.

1 Like

GitHub Personal Access Tokens can be used in place of a username/password combination, so we should probably protect those. I don’t think it’s possible distinguish between just a username and a PAT used like this, so we’ll end up preventing the username case too, if we go down that route.

(I have my doubts about this being anything other than “user error” that we shouldn’t care about at a project level, but I’m not that fussed)

Huh. TIL that github accepts a Personal Access Token if it’s specified in either the username field or the password field.

Luckily, Github provides some formats that we can rely on.

I updated the PR based on the feedback received here. In this update, I added a check for Github tokens.
Anyway, considering the goal is to minimize the impact and help users learn the best practices, I don’t think we need to cover all possible options here.

The discussion here went quiet for the past week.
Considering the current proposal doesn’t change the behavior as the original one, I believe the PR is ready to be merged.
I plan to merge it later today if nobody objects.