Skip to content

Commit cd4b34c

Browse files
committed
Detect unsafe repos and skip them.
In april 2022 a vulnerability was found in git. See https://github.blog/2022-04-12-git-security-vulnerability-announced/. The implemented fix for git is to warn the user and to skip the repo. The warning screws up our output, so we also detect and skip those repos with our own message.
1 parent 1fbd99e commit cd4b34c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ man: mgitstatus.1
1515
test:
1616
# SC1117 Backslash is literal in...
1717
# SC2059 Don't use variables in the printf format string. But we need to or colors won't work
18-
shellcheck -e SC1117,SC2059 mgitstatus
18+
# SC2012 Use find instead of ls, but we need to extract the user id of the .git dir
19+
shellcheck -e SC1117,SC2059,SC2012 mgitstatus
1920

2021
.PHONY: install
2122
install:

mgitstatus

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ C_NEEDS_COMMIT="$C_RED"
147147
C_NEEDS_UPSTREAM="$C_PURPLE"
148148
C_UNTRACKED="$C_CYAN"
149149
C_STASHES="$C_YELLOW"
150+
C_UNSAFE="$C_PURPLE"
151+
152+
# Get current username so we can check .git dir ownership.
153+
ID="$(id -n -u)"
150154

151155
# Find all .git dirs, up to DEPTH levels deep. If DEPTH is 0, the scan is
152156
# infinitely deep
@@ -164,6 +168,15 @@ for DIR in "${@:-"."}"; do
164168
GIT_DIR="$PROJ_DIR/.git"
165169
GIT_CONF="$PROJ_DIR/.git/config"
166170

171+
# Check if the repo is safe (https://github.blog/2022-04-12-git-security-vulnerability-announced/)
172+
if [ -d "$GIT_DIR" ]; then
173+
GIT_DIR_OWNER="$(ls -ld "$GIT_DIR" | awk 'NR==1 {print $3}')"
174+
if [ "$ID" != "$GIT_DIR_OWNER" ]; then
175+
printf "${PROJ_DIR}: ${C_UNSAFE}Unsafe ownership, owned by someone else. Skipping.${C_RESET}\n"
176+
continue
177+
fi
178+
fi
179+
167180
# Check git config for this project to see if we should ignore this repo.
168181
IGNORE=$(git config -f "$GIT_CONF" --bool mgitstatus.ignore)
169182
if [ "$IGNORE" = "true" ]; then

0 commit comments

Comments
 (0)