Skip to content

Commit 2552543

Browse files
committed
credential: warn about git-credential-store [RFC]
git-credential-store saves secrets unencrypted on disk. Warn the user before they type their password, suggesting alternative credential helpers. An alternative could be to warn in "credential-store store". A disadvantage is that the user wouldn't see the warning until after they typed their password, which is less helpful. The warning would appear again every time the user authenticated, which feels too frequently. Signed-off-by: M Hickford <[email protected]>
1 parent 4e746b1 commit 2552543

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

credential.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,13 @@ static int credential_getpass(struct repository *r, struct credential *c)
285285
if (!c->username)
286286
c->username = credential_ask_one("Username", c,
287287
PROMPT_ASKPASS|PROMPT_ECHO);
288-
if (!c->password)
288+
if (!c->password) {
289+
if (c->helpers.nr >= 1 && starts_with(c->helpers.items[0].string, "store"))
290+
warning("git-credential-store saves passwords unencrypted on disk. For alternatives, see gitcredentials(7) or https://git-scm.com/doc/credential-helpers.");
291+
289292
c->password = credential_ask_one("Password", c,
290293
PROMPT_ASKPASS);
294+
}
291295
trace2_region_leave("credential", "interactive", r);
292296

293297
return 0;

t/lib-credential.sh

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ reject() {
6767
helper_test() {
6868
HELPER=$1
6969

70+
# help wanted: expect warning "git-credential-store saves passwords
71+
# unencrypted" when helper equals "store"
7072
test_expect_success "helper ($HELPER) has no existing data" '
7173
check fill $HELPER <<-\EOF
7274
protocol=https

t/t0302-credential-store.sh

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ invalid_credential_test() {
133133
password=askpass-password
134134
--
135135
askpass: Username for '\''https://example.com'\'':
136+
warning: git-credential-store saves passwords unencrypted on disk. For alternatives, see gitcredentials(7) or https://git-scm.com/doc/credential-helpers.
136137
askpass: Password for '\''https://[email protected]'\'':
137138
--
138139
EOF
@@ -155,6 +156,7 @@ test_expect_success 'get: credentials with DOS line endings are invalid' '
155156
password=askpass-password
156157
--
157158
askpass: Username for '\''https://example.com'\'':
159+
warning: git-credential-store saves passwords unencrypted on disk. For alternatives, see gitcredentials(7) or https://git-scm.com/doc/credential-helpers.
158160
askpass: Password for '\''https://[email protected]'\'':
159161
--
160162
EOF
@@ -186,6 +188,7 @@ test_expect_success 'get: credentials with DOS line endings are invalid if path
186188
password=askpass-password
187189
--
188190
askpass: Username for '\''https://example.com/repo.git'\'':
191+
warning: git-credential-store saves passwords unencrypted on disk. For alternatives, see gitcredentials(7) or https://git-scm.com/doc/credential-helpers.
189192
askpass: Password for '\''https://[email protected]/repo.git'\'':
190193
--
191194
EOF

0 commit comments

Comments
 (0)