Skip to content

Commit 600a8cd

Browse files
committed
url: make the updated credentials URL-encoded in the URL
Found-by: Gregory Jefferis Reported-by: Jeroen Ooms Added test 1168 to verify. Bug spotted when doing a redirect. Bug: jeroen/curl#224 Closes #5400
1 parent e2a7a6b commit 600a8cd

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

lib/url.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,12 +2788,14 @@ static CURLcode override_login(struct Curl_easy *data,
27882788

27892789
/* for updated strings, we update them in the URL */
27902790
if(user_changed) {
2791-
uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, 0);
2791+
uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp,
2792+
CURLU_URLENCODE);
27922793
if(uc)
27932794
return Curl_uc_to_curlcode(uc);
27942795
}
27952796
if(passwd_changed) {
2796-
uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, 0);
2797+
uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp,
2798+
CURLU_URLENCODE);
27972799
if(uc)
27982800
return Curl_uc_to_curlcode(uc);
27992801
}

tests/data/Makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \
136136
test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \
137137
test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 \
138138
test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1167 \
139+
test1168 \
139140
\
140141
test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 \
141142
\

tests/data/test1168

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<testcase>
2+
<info>
3+
<keywords>
4+
HTTP
5+
HTTP GET
6+
followlocation
7+
</keywords>
8+
</info>
9+
# Server-side
10+
<reply>
11+
<data>
12+
HTTP/1.1 301 This is a weirdo text message swsclose
13+
Date: Thu, 09 Nov 2010 14:49:00 GMT
14+
Server: test-server/fake
15+
Location: /data/11680002.txt
16+
Connection: close
17+
18+
This server reply is for testing a simple Location: following
19+
20+
</data>
21+
<data2>
22+
HTTP/1.1 200 Followed here fine swsclose
23+
Date: Thu, 09 Nov 2010 14:49:00 GMT
24+
Server: test-server/fake
25+
Content-Length: 52
26+
27+
If this is received, the location following worked
28+
29+
</data2>
30+
<datacheck>
31+
HTTP/1.1 301 This is a weirdo text message swsclose
32+
Date: Thu, 09 Nov 2010 14:49:00 GMT
33+
Server: test-server/fake
34+
Location: /data/11680002.txt
35+
Connection: close
36+
37+
HTTP/1.1 200 Followed here fine swsclose
38+
Date: Thu, 09 Nov 2010 14:49:00 GMT
39+
Server: test-server/fake
40+
Content-Length: 52
41+
42+
If this is received, the location following worked
43+
44+
</datacheck>
45+
</reply>
46+
47+
# Client-side
48+
<client>
49+
<server>
50+
http
51+
</server>
52+
<name>
53+
HTTP redirect with credentials using # in user and password
54+
</name>
55+
<command>
56+
http://%HOSTIP:%HTTPPORT/want/1168 -L -u "catmai#d:#DZaRJYrixKE*gFY"
57+
</command>
58+
</client>
59+
60+
# Verify data after the test has been "shot"
61+
<verify>
62+
<strip>
63+
^User-Agent:.*
64+
</strip>
65+
<protocol>
66+
GET /want/1168 HTTP/1.1
67+
Host: %HOSTIP:%HTTPPORT
68+
Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ==
69+
Accept: */*
70+
71+
GET /data/11680002.txt HTTP/1.1
72+
Host: %HOSTIP:%HTTPPORT
73+
Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ==
74+
Accept: */*
75+
76+
</protocol>
77+
</verify>
78+
</testcase>

0 commit comments

Comments
 (0)