Skip to content

Commit 7f5a382

Browse files
committed
Merge branch 'ab/credentials-in-url-more'
Rename fetch.credentialsInUrl to transfer.credentialsInUrl as the single configuration variable should work both in pushing and fetching. * ab/credentials-in-url-more: transfer doc: move fetch.credentialsInUrl to "transfer" config namespace fetch doc: note "pushurl" caveat about "credentialsInUrl", elaborate
2 parents d0d96b8 + 7281c19 commit 7f5a382

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

Documentation/RelNotes/2.37.0.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ UI, Workflows & Features
5454

5555
* Update the doctype written in gitweb output to xhtml5.
5656

57-
* The "fetch.credentialsInUrl" configuration variable controls what
58-
happens when a URL with embedded login credential is used.
57+
* The "transfer.credentialsInUrl" configuration variable controls what
58+
happens when a URL with embedded login credential is used on either
59+
"fetch" or "push". Credentials are currently only detected in
60+
`remote.<name>.url` config, not `remote.<name>.pushurl`.
5961

6062
* "git revert" learns "--reference" option to use more human-readable
6163
reference to the commit it reverts in the message template it

Documentation/config/fetch.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,3 @@ fetch.writeCommitGraph::
9696
merge and the write may take longer. Having an updated commit-graph
9797
file helps performance of many Git commands, including `git merge-base`,
9898
`git push -f`, and `git log --graph`. Defaults to false.
99-
100-
fetch.credentialsInUrl::
101-
A URL can contain plaintext credentials in the form
102-
`<protocol>://<user>:<password>@<domain>/<path>`. Using such URLs
103-
is not recommended as it exposes the password in multiple ways,
104-
including Git storing the URL as plaintext in the repository config.
105-
The `fetch.credentialsInUrl` option provides instruction for how Git
106-
should react to seeing such a URL, with these values:
107-
+
108-
* `allow` (default): Git will proceed with its activity without warning.
109-
* `warn`: Git will write a warning message to `stderr` when parsing a URL
110-
with a plaintext credential.
111-
* `die`: Git will write a failure message to `stderr` when parsing a URL
112-
with a plaintext credential.

Documentation/config/transfer.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
transfer.credentialsInUrl::
2+
A configured URL can contain plaintext credentials in the form
3+
`<protocol>://<user>:<password>@<domain>/<path>`. You may want
4+
to warn or forbid the use of such configuration (in favor of
5+
using linkgit:git-credential[1]). This will be used on
6+
linkgit:git-clone[1], linkgit:git-fetch[1], linkgit:git-push[1],
7+
and any other direct use of the configured URL.
8+
+
9+
Note that this is currently limited to detecting credentials in
10+
`remote.<name>.url` configuration, it won't detect credentials in
11+
`remote.<name>.pushurl` configuration.
12+
+
13+
You might want to enable this to prevent inadvertent credentials
14+
exposure, e.g. because:
15+
+
16+
* The OS or system where you're running git may not provide way way or
17+
otherwise allow you to configure the permissions of the
18+
configuration file where the username and/or password are stored.
19+
* Even if it does, having such data stored "at rest" might expose you
20+
in other ways, e.g. a backup process might copy the data to another
21+
system.
22+
* The git programs will pass the full URL to one another as arguments
23+
on the command-line, meaning the credentials will be exposed to oher
24+
users on OS's or systems that allow other users to see the full
25+
process list of other users. On linux the "hidepid" setting
26+
documented in procfs(5) allows for configuring this behavior.
27+
+
28+
If such concerns don't apply to you then you probably don't need to be
29+
concerned about credentials exposure due to storing that sensitive
30+
data in git's configuration files. If you do want to use this, set
31+
`transfer.credentialsInUrl` to one of these values:
32+
+
33+
* `allow` (default): Git will proceed with its activity without warning.
34+
* `warn`: Git will write a warning message to `stderr` when parsing a URL
35+
with a plaintext credential.
36+
* `die`: Git will write a failure message to `stderr` when parsing a URL
37+
with a plaintext credential.
38+
139
transfer.fsckObjects::
240
When `fetch.fsckObjects` or `receive.fsckObjects` are
341
not set, the value of this variable is used instead.

remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static void validate_remote_url(struct remote *remote)
623623
struct strbuf redacted = STRBUF_INIT;
624624
int warn_not_die;
625625

626-
if (git_config_get_string_tmp("fetch.credentialsinurl", &value))
626+
if (git_config_get_string_tmp("transfer.credentialsinurl", &value))
627627
return;
628628

629629
if (!strcmp("warn", value))
@@ -633,7 +633,7 @@ static void validate_remote_url(struct remote *remote)
633633
else if (!strcmp("allow", value))
634634
return;
635635
else
636-
die(_("unrecognized value fetch.credentialsInURL: '%s'"), value);
636+
die(_("unrecognized value transfer.credentialsInURL: '%s'"), value);
637637

638638
for (i = 0; i < remote->url_nr; i++) {
639639
struct url_info url_info = { 0 };

t/t5516-fetch-push.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,31 +1836,31 @@ test_expect_success 'refuse to push a hidden ref, and make sure do not pollute t
18361836

18371837
test_expect_success LIBCURL 'fetch warns or fails when using username:password' '
18381838
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1839-
test_must_fail git -c fetch.credentialsInUrl=allow fetch https://username:password@localhost 2>err &&
1839+
test_must_fail git -c transfer.credentialsInUrl=allow fetch https://username:password@localhost 2>err &&
18401840
! grep "$message" err &&
18411841
1842-
test_must_fail git -c fetch.credentialsInUrl=warn fetch https://username:password@localhost 2>err &&
1842+
test_must_fail git -c transfer.credentialsInUrl=warn fetch https://username:password@localhost 2>err &&
18431843
grep "warning: $message" err >warnings &&
18441844
test_line_count = 3 warnings &&
18451845
1846-
test_must_fail git -c fetch.credentialsInUrl=die fetch https://username:password@localhost 2>err &&
1846+
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:password@localhost 2>err &&
18471847
grep "fatal: $message" err >warnings &&
18481848
test_line_count = 1 warnings &&
18491849
1850-
test_must_fail git -c fetch.credentialsInUrl=die fetch https://username:@localhost 2>err &&
1850+
test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:@localhost 2>err &&
18511851
grep "fatal: $message" err >warnings &&
18521852
test_line_count = 1 warnings
18531853
'
18541854

18551855

18561856
test_expect_success LIBCURL 'push warns or fails when using username:password' '
18571857
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1858-
test_must_fail git -c fetch.credentialsInUrl=allow push https://username:password@localhost 2>err &&
1858+
test_must_fail git -c transfer.credentialsInUrl=allow push https://username:password@localhost 2>err &&
18591859
! grep "$message" err &&
18601860
1861-
test_must_fail git -c fetch.credentialsInUrl=warn push https://username:password@localhost 2>err &&
1861+
test_must_fail git -c transfer.credentialsInUrl=warn push https://username:password@localhost 2>err &&
18621862
grep "warning: $message" err >warnings &&
1863-
test_must_fail git -c fetch.credentialsInUrl=die push https://username:password@localhost 2>err &&
1863+
test_must_fail git -c transfer.credentialsInUrl=die push https://username:password@localhost 2>err &&
18641864
grep "fatal: $message" err >warnings &&
18651865
test_line_count = 1 warnings
18661866
'

t/t5601-clone.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,24 @@ test_expect_success 'clone respects GIT_WORK_TREE' '
7373

7474
test_expect_success LIBCURL 'clone warns or fails when using username:password' '
7575
message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
76-
test_must_fail git -c fetch.credentialsInUrl=allow clone https://username:password@localhost attempt1 2>err &&
76+
test_must_fail git -c transfer.credentialsInUrl=allow clone https://username:password@localhost attempt1 2>err &&
7777
! grep "$message" err &&
7878
79-
test_must_fail git -c fetch.credentialsInUrl=warn clone https://username:password@localhost attempt2 2>err &&
79+
test_must_fail git -c transfer.credentialsInUrl=warn clone https://username:password@localhost attempt2 2>err &&
8080
grep "warning: $message" err >warnings &&
8181
test_line_count = 2 warnings &&
8282
83-
test_must_fail git -c fetch.credentialsInUrl=die clone https://username:password@localhost attempt3 2>err &&
83+
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:password@localhost attempt3 2>err &&
8484
grep "fatal: $message" err >warnings &&
8585
test_line_count = 1 warnings &&
8686
87-
test_must_fail git -c fetch.credentialsInUrl=die clone https://username:@localhost attempt3 2>err &&
87+
test_must_fail git -c transfer.credentialsInUrl=die clone https://username:@localhost attempt3 2>err &&
8888
grep "fatal: $message" err >warnings &&
8989
test_line_count = 1 warnings
9090
'
9191

9292
test_expect_success LIBCURL 'clone does not detect username:password when it is https://username@domain:port/' '
93-
test_must_fail git -c fetch.credentialsInUrl=warn clone https://username@localhost:8080 attempt3 2>err &&
93+
test_must_fail git -c transfer.credentialsInUrl=warn clone https://username@localhost:8080 attempt3 2>err &&
9494
! grep "uses plaintext credentials" err
9595
'
9696

0 commit comments

Comments
 (0)