fix: git commit date parsing for non-English locales #4653
+83
−82
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3338
Description:
TruffleHog fails to parse git commit dates when the system locale is non-English (e.g., German outputs
Sa.instead ofSat) preventing users from scanning git repos(all git-based sources like local git repo, github, gitlab, etc). This is because the format that is being used--date=format:%a %b %d %H:%M:%S %Y %zis dependent onstrftime(3)C library function which is locale dependent(uses POSIX LC_ALL, LC_TIME, LANG). SettingLC_ALL=Cor any other locale on the user's side likeLC_ALL=de_DE.UTF-8 trufflehog ...doesn't help because the code overwrites the subprocess environment:trufflehog/pkg/gitparse/gitparse.go
Lines 257 to 273 in 4e02afb
From os/exec go doc:
This means git only receives
GIT_DIRand no locale settings. Rather than fixing env inheritance or addingLC_TIME=C, this PR switches to--date=iso-strictwhich outputs locale-independent ISO 8601 timestamps(2024-09-28T07:59:21+00:00). I think this is a pretty good solution: iso format has been stable since Git 2.2 (2014), requires no environment manipulation, and uses Go's nativetime.RFC3339parser.Error message when parsing:
Tested on homebrew git on mac(apple git seems to completely ignoring locales) and linux (debian)
Checklist:
make test-community)?make lintthis requires golangci-lint)?