blob: 47032d96c0ffc79c8d0b1b41cce7c914c2ff14a4 [file] [log] [blame]
Tim Duesterhusd371e992021-04-15 21:45:58 +02001varnishtest "normalize-uri tests"
2#REQUIRE_VERSION=2.4
3
4# This reg-test tests the http-request normalize-uri action.
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
10 txresp
Tim Duesterhus2e4a18e2021-04-21 21:20:36 +020011} -repeat 63 -start
Tim Duesterhusd371e992021-04-15 21:45:58 +020012
13haproxy h1 -conf {
Amaury Denoyellea9e639a2021-05-06 15:50:12 +020014 global
15 expose-experimental-directives
16
Tim Duesterhusd371e992021-04-15 21:45:58 +020017 defaults
18 mode http
19 timeout connect 1s
20 timeout client 1s
21 timeout server 1s
22
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020023 frontend fe_path_merge_slashes
24 bind "fd@${fe_path_merge_slashes}"
Tim Duesterhusd371e992021-04-15 21:45:58 +020025
26 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020027 http-request normalize-uri path-merge-slashes
Tim Duesterhusd371e992021-04-15 21:45:58 +020028 http-request set-var(txn.after) url
29
30 http-response add-header before %[var(txn.before)]
31 http-response add-header after %[var(txn.after)]
32
33 default_backend be
34
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020035 frontend fe_path_strip_dotdot
36 bind "fd@${fe_path_strip_dotdot}"
Tim Duesterhus9982fc22021-04-15 21:45:59 +020037
38 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020039 http-request normalize-uri path-strip-dotdot
Tim Duesterhus9982fc22021-04-15 21:45:59 +020040 http-request set-var(txn.after) url
41
Tim Duesterhus560e1a62021-04-15 21:46:00 +020042 http-request set-uri %[var(txn.before)]
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020043 http-request normalize-uri path-strip-dotdot full
Tim Duesterhus560e1a62021-04-15 21:46:00 +020044 http-request set-var(txn.after_full) url
45
Tim Duesterhus9982fc22021-04-15 21:45:59 +020046 http-response add-header before %[var(txn.before)]
47 http-response add-header after %[var(txn.after)]
Tim Duesterhus560e1a62021-04-15 21:46:00 +020048 http-response add-header after-full %[var(txn.after_full)]
Tim Duesterhus9982fc22021-04-15 21:45:59 +020049
50 default_backend be
51
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020052 frontend fe_sort_query_by_name
53 bind "fd@${fe_sort_query_by_name}"
Tim Duesterhusd7b89be2021-04-15 21:46:01 +020054
55 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020056 http-request normalize-uri query-sort-by-name
Tim Duesterhusd7b89be2021-04-15 21:46:01 +020057 http-request set-var(txn.after) url
58
59 http-response add-header before %[var(txn.before)]
60 http-response add-header after %[var(txn.after)]
61
62 default_backend be
63
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020064 frontend fe_percent_to_uppercase
65 bind "fd@${fe_percent_to_uppercase}"
Tim Duesterhusa4071932021-04-15 21:46:02 +020066
67 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020068 http-request normalize-uri percent-to-uppercase
Tim Duesterhusa4071932021-04-15 21:46:02 +020069 http-request set-var(txn.after) url
70
71 http-response add-header before %[var(txn.before)]
72 http-response add-header after %[var(txn.after)]
73
74 default_backend be
75
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020076 frontend fe_percent_to_uppercase_strict
77 bind "fd@${fe_percent_to_uppercase_strict}"
Tim Duesterhusa4071932021-04-15 21:46:02 +020078
79 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020080 http-request normalize-uri percent-to-uppercase strict
Tim Duesterhusa4071932021-04-15 21:46:02 +020081 http-request set-var(txn.after) url
82
83 http-response add-header before %[var(txn.before)]
84 http-response add-header after %[var(txn.after)]
85
86 default_backend be
87
Maximilian Maderff3bb8b2021-04-21 00:22:50 +020088 frontend fe_dot
89 bind "fd@${fe_dot}"
90
91 http-request set-var(txn.before) url
92 http-request normalize-uri path-strip-dot
93 http-request set-var(txn.after) url
94
95 http-response add-header before %[var(txn.before)]
96 http-response add-header after %[var(txn.after)]
97
98 default_backend be
99
Tim Duesterhus2e4a18e2021-04-21 21:20:36 +0200100 frontend fe_percent_decode_unreserved
101 bind "fd@${fe_percent_decode_unreserved}"
102
103 http-request set-var(txn.before) url
104 http-request normalize-uri percent-decode-unreserved
105 http-request set-var(txn.after) url
106
107 http-response add-header before %[var(txn.before)]
108 http-response add-header after %[var(txn.after)]
109
110 default_backend be
111
112 frontend fe_percent_decode_unreserved_strict
113 bind "fd@${fe_percent_decode_unreserved_strict}"
114
115 http-request set-var(txn.before) url
116 http-request normalize-uri percent-decode-unreserved strict
117 http-request set-var(txn.after) url
118
119 http-response add-header before %[var(txn.before)]
120 http-response add-header after %[var(txn.after)]
121
122 default_backend be
123
Tim Duesterhusd371e992021-04-15 21:45:58 +0200124 backend be
125 server s1 ${s1_addr}:${s1_port}
126
127} -start
128
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200129client c1 -connect ${h1_fe_path_merge_slashes_sock} {
Tim Duesterhusd371e992021-04-15 21:45:58 +0200130 txreq -url "/foo/bar"
131 rxresp
132 expect resp.http.before == "/foo/bar"
133 expect resp.http.after == "/foo/bar"
134
135 txreq -url "/foo//bar"
136 rxresp
137 expect resp.http.before == "/foo//bar"
138 expect resp.http.after == "/foo/bar"
139
140 txreq -url "/foo///bar"
141 rxresp
142 expect resp.http.before == "/foo///bar"
143 expect resp.http.after == "/foo/bar"
144
145 txreq -url "///foo///bar"
146 rxresp
147 expect resp.http.before == "///foo///bar"
148 expect resp.http.after == "/foo/bar"
149
150 txreq -url "///foo/bar"
151 rxresp
152 expect resp.http.before == "///foo/bar"
153 expect resp.http.after == "/foo/bar"
154
155 txreq -url "///foo///bar///"
156 rxresp
157 expect resp.http.before == "///foo///bar///"
158 expect resp.http.after == "/foo/bar/"
159
160 txreq -url "///"
161 rxresp
162 expect resp.http.before == "///"
163 expect resp.http.after == "/"
164
165 txreq -url "/foo?bar=///"
166 rxresp
167 expect resp.http.before == "/foo?bar=///"
168 expect resp.http.after == "/foo?bar=///"
169
170 txreq -url "//foo?bar=///"
171 rxresp
172 expect resp.http.before == "//foo?bar=///"
173 expect resp.http.after == "/foo?bar=///"
174
175 txreq -req OPTIONS -url "*"
176 rxresp
177 expect resp.http.before == "*"
178 expect resp.http.after == "*"
179} -run
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200180
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200181client c2 -connect ${h1_fe_path_strip_dotdot_sock} {
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200182 txreq -url "/foo/bar"
183 rxresp
184 expect resp.http.before == "/foo/bar"
185 expect resp.http.after == "/foo/bar"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200186 expect resp.http.after-full == "/foo/bar"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200187
188 txreq -url "/foo/.."
189 rxresp
190 expect resp.http.before == "/foo/.."
191 expect resp.http.after == "/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200192 expect resp.http.after-full == "/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200193
194 txreq -url "/foo/../"
195 rxresp
196 expect resp.http.before == "/foo/../"
197 expect resp.http.after == "/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200198 expect resp.http.after-full == "/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200199
200 txreq -url "/foo/bar/../"
201 rxresp
202 expect resp.http.before == "/foo/bar/../"
203 expect resp.http.after == "/foo/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200204 expect resp.http.after-full == "/foo/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200205
206 txreq -url "/foo/../bar"
207 rxresp
208 expect resp.http.before == "/foo/../bar"
209 expect resp.http.after == "/bar"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200210 expect resp.http.after-full == "/bar"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200211
212 txreq -url "/foo/../bar/"
213 rxresp
214 expect resp.http.before == "/foo/../bar/"
215 expect resp.http.after == "/bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200216 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200217
218 txreq -url "/foo/../../bar/"
219 rxresp
220 expect resp.http.before == "/foo/../../bar/"
221 expect resp.http.after == "/../bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200222 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200223
224 txreq -url "/foo//../../bar/"
225 rxresp
226 expect resp.http.before == "/foo//../../bar/"
227 expect resp.http.after == "/bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200228 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200229
230 txreq -url "/foo/?bar=/foo/../"
231 rxresp
232 expect resp.http.before == "/foo/?bar=/foo/../"
233 expect resp.http.after == "/foo/?bar=/foo/../"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200234 expect resp.http.after-full == "/foo/?bar=/foo/../"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200235
236 txreq -url "/foo/../?bar=/foo/../"
237 rxresp
238 expect resp.http.before == "/foo/../?bar=/foo/../"
239 expect resp.http.after == "/?bar=/foo/../"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200240 expect resp.http.after-full == "/?bar=/foo/../"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200241
242 txreq -req OPTIONS -url "*"
243 rxresp
244 expect resp.http.before == "*"
245 expect resp.http.after == "*"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200246 expect resp.http.after-full == "*"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200247} -run
Tim Duesterhusd7b89be2021-04-15 21:46:01 +0200248
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200249client c3 -connect ${h1_fe_sort_query_by_name_sock} {
Tim Duesterhusd7b89be2021-04-15 21:46:01 +0200250 txreq -url "/?a=a"
251 rxresp
252 expect resp.http.before == "/?a=a"
253 expect resp.http.after == "/?a=a"
254
255 txreq -url "/?a=a&z=z"
256 rxresp
257 expect resp.http.before == "/?a=a&z=z"
258 expect resp.http.after == "/?a=a&z=z"
259
260 txreq -url "/?z=z&a=a"
261 rxresp
262 expect resp.http.before == "/?z=z&a=a"
263 expect resp.http.after == "/?a=a&z=z"
264
265 txreq -url "/?a=z&z=a"
266 rxresp
267 expect resp.http.before == "/?a=z&z=a"
268 expect resp.http.after == "/?a=z&z=a"
269
270 txreq -url "/?z=a&a=z"
271 rxresp
272 expect resp.http.before == "/?z=a&a=z"
273 expect resp.http.after == "/?a=z&z=a"
274
275 txreq -url "/?c&b&a&z&x&y"
276 rxresp
277 expect resp.http.before == "/?c&b&a&z&x&y"
278 expect resp.http.after == "/?a&b&c&x&y&z"
279
280 txreq -url "/?a=&aa=&aaa=&aaaa="
281 rxresp
282 expect resp.http.before == "/?a=&aa=&aaa=&aaaa="
283 expect resp.http.after == "/?a=&aa=&aaa=&aaaa="
284
285 txreq -url "/?aaaa=&a=&aa=&aaa="
286 rxresp
287 expect resp.http.before == "/?aaaa=&a=&aa=&aaa="
288 expect resp.http.after == "/?a=&aa=&aaa=&aaaa="
289
290 txreq -url "/?a=5&a=3&a=1&a=2&a=4"
291 rxresp
292 expect resp.http.before == "/?a=5&a=3&a=1&a=2&a=4"
293 expect resp.http.after == "/?a=5&a=3&a=1&a=2&a=4"
294
295 txreq -url "/?a=5&b=3&a=1&a=2&b=4"
296 rxresp
297 expect resp.http.before == "/?a=5&b=3&a=1&a=2&b=4"
298 expect resp.http.after == "/?a=5&a=1&a=2&b=3&b=4"
299
300 txreq -url "/"
301 rxresp
302 expect resp.http.before == "/"
303 expect resp.http.after == "/"
304
305 txreq -url "/?"
306 rxresp
307 expect resp.http.before == "/?"
308 expect resp.http.after == "/?"
309
310 txreq -req OPTIONS -url "*"
311 rxresp
312 expect resp.http.before == "*"
313 expect resp.http.after == "*"
314} -run
Tim Duesterhusa4071932021-04-15 21:46:02 +0200315
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200316client c4 -connect ${h1_fe_percent_to_uppercase_sock} {
Tim Duesterhusa4071932021-04-15 21:46:02 +0200317 txreq -url "/a?a=a"
318 rxresp
319 expect resp.http.before == "/a?a=a"
320 expect resp.http.after == "/a?a=a"
321
322 txreq -url "/%aa?a=%aa"
323 rxresp
324 expect resp.http.before == "/%aa?a=%aa"
325 expect resp.http.after == "/%AA?a=%AA"
326
327 txreq -url "/%zz?a=%zz"
328 rxresp
329 expect resp.status == 200
330 expect resp.http.before == "/%zz?a=%zz"
331 expect resp.http.after == "/%zz?a=%zz"
332
333 txreq -req OPTIONS -url "*"
334 rxresp
335 expect resp.http.before == "*"
336 expect resp.http.after == "*"
337} -run
338
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200339client c5 -connect ${h1_fe_percent_to_uppercase_strict_sock} {
Tim Duesterhusa4071932021-04-15 21:46:02 +0200340 txreq -url "/a?a=a"
341 rxresp
342 expect resp.http.before == "/a?a=a"
343 expect resp.http.after == "/a?a=a"
344
345 txreq -url "/%aa?a=%aa"
346 rxresp
347 expect resp.http.before == "/%aa?a=%aa"
348 expect resp.http.after == "/%AA?a=%AA"
349
350 txreq -url "/%zz?a=%zz"
351 rxresp
352 expect resp.status == 400
353} -run
Maximilian Maderff3bb8b2021-04-21 00:22:50 +0200354
355client c6 -connect ${h1_fe_dot_sock} {
356 txreq -url "/"
357 rxresp
358 expect resp.http.before == "/"
359 expect resp.http.after == "/"
360
361 txreq -url "/a/b"
362 rxresp
363 expect resp.http.before == "/a/b"
364 expect resp.http.after == "/a/b"
365
366 txreq -url "/."
367 rxresp
368 expect resp.http.before == "/."
369 expect resp.http.after == "/"
370
371 txreq -url "/./"
372 rxresp
373 expect resp.http.before == "/./"
374 expect resp.http.after == "/"
375
376 txreq -url "/a/."
377 rxresp
378 expect resp.http.before == "/a/."
379 expect resp.http.after == "/a/"
380
381 txreq -url "/a."
382 rxresp
383 expect resp.http.before == "/a."
384 expect resp.http.after == "/a."
385
386 txreq -url "/.a"
387 rxresp
388 expect resp.http.before == "/.a"
389 expect resp.http.after == "/.a"
390
391 txreq -url "/a/."
392 rxresp
393 expect resp.http.before == "/a/."
394 expect resp.http.after == "/a/"
395
396 txreq -url "/a/./"
397 rxresp
398 expect resp.http.before == "/a/./"
399 expect resp.http.after == "/a/"
400
401 txreq -url "/a/./a"
402 rxresp
403 expect resp.http.before == "/a/./a"
404 expect resp.http.after == "/a/a"
405
406 txreq -url "/a/../"
407 rxresp
408 expect resp.http.before == "/a/../"
409 expect resp.http.after == "/a/../"
410
411 txreq -url "/a/../a"
412 rxresp
413 expect resp.http.before == "/a/../a"
414 expect resp.http.after == "/a/../a"
415
416 txreq -url "/?a=/./"
417 rxresp
418 expect resp.http.before == "/?a=/./"
419 expect resp.http.after == "/?a=/./"
420} -run
Tim Duesterhus2e4a18e2021-04-21 21:20:36 +0200421
422client c7 -connect ${h1_fe_percent_decode_unreserved_sock} {
423 txreq -url "/a?a=a"
424 rxresp
425 expect resp.http.before == "/a?a=a"
426 expect resp.http.after == "/a?a=a"
427
428 txreq -url "/%61?%61=%61"
429 rxresp
430 expect resp.http.before == "/%61?%61=%61"
431 expect resp.http.after == "/a?a=a"
432
433 txreq -url "/%3F?foo=bar"
434 rxresp
435 expect resp.http.before == "/%3F?foo=bar"
436 expect resp.http.after == "/%3F?foo=bar"
437
438 txreq -url "/%%36%36"
439 rxresp
440 expect resp.status == 200
441 expect resp.http.before == "/%%36%36"
442 expect resp.http.after == "/%66"
443
444 txreq -req OPTIONS -url "*"
445 rxresp
446 expect resp.http.before == "*"
447 expect resp.http.after == "*"
448} -run
449
450client c8 -connect ${h1_fe_percent_decode_unreserved_strict_sock} {
451 txreq -url "/a?a=a"
452 rxresp
453 expect resp.http.before == "/a?a=a"
454 expect resp.http.after == "/a?a=a"
455
456 txreq -url "/%61?%61=%61"
457 rxresp
458 expect resp.http.before == "/%61?%61=%61"
459 expect resp.http.after == "/a?a=a"
460
461 txreq -url "/%3F?foo=bar"
462 rxresp
463 expect resp.http.before == "/%3F?foo=bar"
464 expect resp.http.after == "/%3F?foo=bar"
465
466 txreq -url "/%%36%36"
467 rxresp
468 expect resp.status == 400
469} -run