less is more

心のフルスタックエンジニア👨‍💻バイブスでコードを書いています🤘

Gitに深刻な脆弱性が報告されたのでアップデートする

CVE-2020-5260 として報告されているissue

malicious URLs may cause Git to present stored credentials to the wrong server · Advisory · git/git · GitHub

要約すると、攻撃者がリポジトリに細工をしておくと、git cloneの際にユーザー の認証情報を窃取することができるというもの。

仕組みとしては credential.helper を利用しているらしい。

credential.helper についての説明は以下を参照。
Git - 認証情報の保存

毎回パスワード聞かれるのを回避するための機能。

ワークアラウンド

パッチバージョンがリリースされているのでアップデートするのが安心だが、ひとまず credential.helper を使わないようにすることでも回避できる。

git config --unset credential.helper
git config --global --unset credential.helper
git config --system --unset credential.helper

バージョンアップ

自分のバージョンを確認。

git --version

脆弱なバージョンはこちら。

<= 2.17.3, 2.18.2, 2.19.3, 2.20.2, 2.21.1, 2.22.2, 2.23.1, 2.24.1, 2.25.2, 2.26.0

パッチだけ当てればいいが、gitはマイナーバージョンを上げても互換性が崩れることは比較的少ないので、最新に上げる。

homebrewで入れている場合は

brew upgrade git

yum の場合は yum update git でいいが、古い1系のが入ってる場合が往々にしてある。その場合は1系のままなので、一度削除する必要がある。

ソースからビルドするので諸々ライブラリを入れる。

sudo yum -y install gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf
cd /usr/local/src/
sudo wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.1.tar.gz
sudo tar xzvf git-2.26.1.tar.gz
sudo rm -rf git-2.26.1.tar.gz
cd git-2.26.1/
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

ubuntuの場合も一応。

apt-get install software-properties-common
add-apt-repository ppa:git-core/ppa
# NO_PUBKEYのエラーが出た場合
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys {key}
apt-get update
apt-get upgrade git

最後に

submoduleも影響を受けるので、割と深刻。