Skip to content

Conversation

@ethomson
Copy link
Member

If fetching from an anonymous remote via its URL, then the URL gets
written into the FETCH_HEAD reference. This is mainly done to give
valuable context to some commands, like for example git-merge(1), which
will put the URL into the generated MERGE_MSG. As a result, what gets
written into FETCH_HEAD may become public in some cases. This is
especially important considering that URLs may contain credentials, e.g.
when cloning 'https://foo:bar@example.com/repo' we persist the complete
URL into FETCH_HEAD and put it without any kind of sanitization into the
MERGE_MSG. This is obviously bad, as your login data has now just leaked
as soon as you do git-push(1).

When writing the URL into FETCH_HEAD, upstream git does strip
credentials first. Let's do the same by trying to parse the remote URL
as a "real" URL, removing any credentials and then re-formatting the
URL. In case this fails, e.g. when it's a file path or not a valid URL,
we just fall back to using the URL as-is without any sanitization. Add
tests to verify our behaviour.

If fetching from an anonymous remote via its URL, then the URL gets
written into the FETCH_HEAD reference. This is mainly done to give
valuable context to some commands, like for example git-merge(1), which
will put the URL into the generated MERGE_MSG. As a result, what gets
written into FETCH_HEAD may become public in some cases. This is
especially important considering that URLs may contain credentials, e.g.
when cloning 'https://foo:bar@example.com/repo' we persist the complete
URL into FETCH_HEAD and put it without any kind of sanitization into the
MERGE_MSG. This is obviously bad, as your login data has now just leaked
as soon as you do git-push(1).

When writing the URL into FETCH_HEAD, upstream git does strip
credentials first. Let's do the same by trying to parse the remote URL
as a "real" URL, removing any credentials and then re-formatting the
URL. In case this fails, e.g. when it's a file path or not a valid URL,
we just fall back to using the URL as-is without any sanitization. Add
tests to verify our behaviour.
@ethomson ethomson requested a review from pks-t March 30, 2020 10:11
@ethomson
Copy link
Member Author

Let's sneak this in before v0.28.5. 😀

@pks-t
Copy link
Member

pks-t commented Mar 30, 2020

Oops, did I somehow drop your backport again? I thought I actually cherry-picked it.

@pks-t
Copy link
Member

pks-t commented Mar 30, 2020

@ethomson: looks good to me, thanks for the backport! We should add one more entry to the changelog, though.

Document that we no longer erroneously include credentials in the
FETCH_HEAD file.
@ethomson
Copy link
Member Author

Added a changelog entry.

@pks-t pks-t merged commit 7a2b969 into maint/v0.28 Mar 31, 2020
@pks-t pks-t deleted the ethomson/v0.28.5 branch March 31, 2020 13:42
@pks-t
Copy link
Member

pks-t commented Mar 31, 2020

Thanks, @ethomson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants