git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Limited local file inclusion with .mailmap symlinks and git-archive

From
Blake Burkhart <bburky@bburky.com>
Date
Feb 13, 2021, 17:49 UTC
Message-ID
<CAP3OtXj15f9XV=Rzz2oBXQ1TQH3WWKJGBbeaWrmp6Ha4ZTn9nA@mail.gmail.com>

Git's mailmap implementation first tries using the blob from the repository, but also supports using a local (possibly uncommitted) .mailmap file. When reading from the local file, git will follow symlinks. If a symlink is committed to a repository named .mailmap, git will parse the file on the other side of the symlink if the repository is cloned locally.

Git log supports an %aN placeholder which prints the result of the mailmap, if it is possible for this value to be sent to an attacker this could become a local file inclusion concern. With git-archive it is possible to use $Format:%aN$ to include this value in an exported archive.

Running git on bare repos or using git archive --remote=... is unaffected because a local file is never used, only the in-repo blob.

Git's mailmap parser is very forgiving, it reads in each line, skips lines starting with #, then considers whatever it finds between < and

> as the email address. It is even possible to use binary files as a

.mailmap. As a demonstration I used a symlink to /proc/self/exe (which itself is a symlink to /usr/bin/git). The string [--exec-path[= was extracted from the binary as the author name.

git init mailmap cd mailmap ln -s /proc/self/exe .mailmap echo "test export-subst" > .gitattributes echo '$Format:%aN$' > test git add .mailmap .gitattributes test git commit -m "test" --author="foo <path>" cd ..

# Pretend you're cloning from the internet... git clone mailmap mailmap-clone cd mailmap-clone git archive --format=tar HEAD # Output contains [--exec-path[=

These are unaffected:

cd .. git --git-dir=mailmap/.git archive --format=tar HEAD git archive --remote=git://localhost/ --format=tar HEAD

I reported this issue to the private security list first and discussed this issue with Peff. This is similar to existing concerns with .gitmodules, .gitattributes and .gitignore. Git already disallows checking out a .gitmodules file from a repository, and I understand there are in progress patches to add similar protection for .gitattributes and .gitignore. Please ensure the .mailmap file gets similar symlink protection.

Exploitability is limited because the targeted file must contain a string formatted like <foo> known to the attacker, or attacker controlled. Also, most automated build systems that checkout code are sandboxed and prepared to run arbitrary code already (it is technically possible to read potentially sensitive variables from /proc/self/environ with this, but is very limited because it contains null bytes).

-- Blake Burkhart

Next: Jeff King
Message 1 of 25 in “Limited local file inclusion with .mailmap symlinks and git-archive”
  1. Blake BurkhartFeb 13, 2021
  2. Jeff KingFeb 15, 2021
  3. 1/2 fsck: make symlinked .gitignore and .gitattributes a warningJeff King, Feb 15, 2021
  4. Ævar Arnfjörð BjarmasonFeb 16, 2021
  5. Jeff KingFeb 16, 2021
  6. Junio C HamanoFeb 16, 2021
  7. Jeff KingFeb 16, 2021
  8. Jeff KingFeb 16, 2021
  9. 0/6 open in-tree files with O_NOFOLLOWJeff King, Feb 16, 2021
  10. 1/6 add open_nofollow() helperJeff King, Feb 16, 2021
  11. Jeff KingFeb 16, 2021
  12. Taylor BlauFeb 16, 2021
  13. Jeff KingFeb 16, 2021
  14. Taylor BlauFeb 16, 2021
  15. Taylor BlauFeb 16, 2021
  16. Jeff KingFeb 16, 2021
  17. 2/6 attr: convert "macro_ok" into a flags fieldJeff King, Feb 16, 2021
  18. 4/6 attr: do not respect symlinks for in-tree .gitattributesJeff King, Feb 16, 2021
  19. 5/6 exclude: do not respect symlinks for in-tree .gitignoreJeff King, Feb 16, 2021
  20. 3/6 exclude: add flags parameter to add_patterns()Jeff King, Feb 16, 2021
  21. 6/6 mailmap: do not respect symlinks for in-tree .mailmapJeff King, Feb 16, 2021
  22. Jeff KingFeb 16, 2021
  23. Junio C HamanoFeb 25, 2021
  24. Jeff KingFeb 26, 2021
  25. 2/2 disallow symlinked .mailmap filesJeff King, Feb 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.