blob: 82c810718df18a26a79eb80440d59f97864724cd [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
Christopher Faulete07f8b52022-02-28 17:04:37 +010010 txresp -hdr "connection: close"
Tim Duesterhusdec1c362021-05-10 17:28:26 +020011} -repeat 70 -start
Tim Duesterhusd371e992021-04-15 21:45:58 +020012
13haproxy h1 -conf {
Amaury Denoyellea9e639a2021-05-06 15:50:12 +020014 global
Willy Tarreaue1465c12021-05-09 14:41:41 +020015 # WT: limit false-positives causing "HTTP header incomplete" due to
16 # idle server connections being randomly used and randomly expiring
17 # under us.
18 tune.idle-pool.shared off
Amaury Denoyellea9e639a2021-05-06 15:50:12 +020019 expose-experimental-directives
20
Tim Duesterhusd371e992021-04-15 21:45:58 +020021 defaults
22 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010023 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
24 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
25 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Tim Duesterhusd371e992021-04-15 21:45:58 +020026
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020027 frontend fe_path_merge_slashes
28 bind "fd@${fe_path_merge_slashes}"
Tim Duesterhusd371e992021-04-15 21:45:58 +020029
30 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020031 http-request normalize-uri path-merge-slashes
Tim Duesterhusd371e992021-04-15 21:45:58 +020032 http-request set-var(txn.after) url
33
34 http-response add-header before %[var(txn.before)]
35 http-response add-header after %[var(txn.after)]
36
37 default_backend be
38
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020039 frontend fe_path_strip_dotdot
40 bind "fd@${fe_path_strip_dotdot}"
Tim Duesterhus9982fc22021-04-15 21:45:59 +020041
42 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020043 http-request normalize-uri path-strip-dotdot
Tim Duesterhus9982fc22021-04-15 21:45:59 +020044 http-request set-var(txn.after) url
45
Tim Duesterhus560e1a62021-04-15 21:46:00 +020046 http-request set-uri %[var(txn.before)]
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020047 http-request normalize-uri path-strip-dotdot full
Tim Duesterhus560e1a62021-04-15 21:46:00 +020048 http-request set-var(txn.after_full) url
49
Tim Duesterhus9982fc22021-04-15 21:45:59 +020050 http-response add-header before %[var(txn.before)]
51 http-response add-header after %[var(txn.after)]
Tim Duesterhus560e1a62021-04-15 21:46:00 +020052 http-response add-header after-full %[var(txn.after_full)]
Tim Duesterhus9982fc22021-04-15 21:45:59 +020053
54 default_backend be
55
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020056 frontend fe_sort_query_by_name
57 bind "fd@${fe_sort_query_by_name}"
Tim Duesterhusd7b89be2021-04-15 21:46:01 +020058
59 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020060 http-request normalize-uri query-sort-by-name
Tim Duesterhusd7b89be2021-04-15 21:46:01 +020061 http-request set-var(txn.after) url
62
63 http-response add-header before %[var(txn.before)]
64 http-response add-header after %[var(txn.after)]
65
66 default_backend be
67
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020068 frontend fe_percent_to_uppercase
69 bind "fd@${fe_percent_to_uppercase}"
Tim Duesterhusa4071932021-04-15 21:46:02 +020070
71 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020072 http-request normalize-uri percent-to-uppercase
Tim Duesterhusa4071932021-04-15 21:46:02 +020073 http-request set-var(txn.after) url
74
75 http-response add-header before %[var(txn.before)]
76 http-response add-header after %[var(txn.after)]
77
78 default_backend be
79
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020080 frontend fe_percent_to_uppercase_strict
81 bind "fd@${fe_percent_to_uppercase_strict}"
Tim Duesterhusa4071932021-04-15 21:46:02 +020082
83 http-request set-var(txn.before) url
Tim Duesterhus5be6ab22021-04-17 11:21:10 +020084 http-request normalize-uri percent-to-uppercase strict
Tim Duesterhusa4071932021-04-15 21:46:02 +020085 http-request set-var(txn.after) url
86
87 http-response add-header before %[var(txn.before)]
88 http-response add-header after %[var(txn.after)]
89
90 default_backend be
91
Maximilian Maderff3bb8b2021-04-21 00:22:50 +020092 frontend fe_dot
93 bind "fd@${fe_dot}"
94
95 http-request set-var(txn.before) url
96 http-request normalize-uri path-strip-dot
97 http-request set-var(txn.after) url
98
99 http-response add-header before %[var(txn.before)]
100 http-response add-header after %[var(txn.after)]
101
102 default_backend be
103
Tim Duesterhus2e4a18e2021-04-21 21:20:36 +0200104 frontend fe_percent_decode_unreserved
105 bind "fd@${fe_percent_decode_unreserved}"
106
107 http-request set-var(txn.before) url
108 http-request normalize-uri percent-decode-unreserved
109 http-request set-var(txn.after) url
110
111 http-response add-header before %[var(txn.before)]
112 http-response add-header after %[var(txn.after)]
113
114 default_backend be
115
116 frontend fe_percent_decode_unreserved_strict
117 bind "fd@${fe_percent_decode_unreserved_strict}"
118
119 http-request set-var(txn.before) url
120 http-request normalize-uri percent-decode-unreserved strict
121 http-request set-var(txn.after) url
122
123 http-response add-header before %[var(txn.before)]
124 http-response add-header after %[var(txn.after)]
125
126 default_backend be
127
Tim Duesterhusc9e05ab2021-05-10 17:28:25 +0200128 frontend fe_fragment_strip
129 bind "fd@${fe_fragment_strip}"
130
131 http-request set-var(txn.before) url
132 http-request normalize-uri fragment-strip
133 http-request set-var(txn.after) url
134
135 http-response add-header before %[var(txn.before)]
136 http-response add-header after %[var(txn.after)]
137
138 default_backend be
139
Tim Duesterhusdec1c362021-05-10 17:28:26 +0200140 frontend fe_fragment_encode
141 bind "fd@${fe_fragment_encode}"
142
143 http-request set-var(txn.before) url
144 http-request normalize-uri fragment-encode
145 http-request set-var(txn.after) url
146
147 http-response add-header before %[var(txn.before)]
148 http-response add-header after %[var(txn.after)]
149
150 default_backend be
151
Tim Duesterhusd371e992021-04-15 21:45:58 +0200152 backend be
153 server s1 ${s1_addr}:${s1_port}
154
155} -start
156
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200157client c1 -connect ${h1_fe_path_merge_slashes_sock} {
Tim Duesterhusd371e992021-04-15 21:45:58 +0200158 txreq -url "/foo/bar"
159 rxresp
160 expect resp.http.before == "/foo/bar"
161 expect resp.http.after == "/foo/bar"
162
163 txreq -url "/foo//bar"
164 rxresp
165 expect resp.http.before == "/foo//bar"
166 expect resp.http.after == "/foo/bar"
167
168 txreq -url "/foo///bar"
169 rxresp
170 expect resp.http.before == "/foo///bar"
171 expect resp.http.after == "/foo/bar"
172
173 txreq -url "///foo///bar"
174 rxresp
175 expect resp.http.before == "///foo///bar"
176 expect resp.http.after == "/foo/bar"
177
178 txreq -url "///foo/bar"
179 rxresp
180 expect resp.http.before == "///foo/bar"
181 expect resp.http.after == "/foo/bar"
182
183 txreq -url "///foo///bar///"
184 rxresp
185 expect resp.http.before == "///foo///bar///"
186 expect resp.http.after == "/foo/bar/"
187
188 txreq -url "///"
189 rxresp
190 expect resp.http.before == "///"
191 expect resp.http.after == "/"
192
193 txreq -url "/foo?bar=///"
194 rxresp
195 expect resp.http.before == "/foo?bar=///"
196 expect resp.http.after == "/foo?bar=///"
197
198 txreq -url "//foo?bar=///"
199 rxresp
200 expect resp.http.before == "//foo?bar=///"
201 expect resp.http.after == "/foo?bar=///"
202
203 txreq -req OPTIONS -url "*"
204 rxresp
205 expect resp.http.before == "*"
206 expect resp.http.after == "*"
207} -run
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200208
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200209client c2 -connect ${h1_fe_path_strip_dotdot_sock} {
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200210 txreq -url "/foo/bar"
211 rxresp
212 expect resp.http.before == "/foo/bar"
213 expect resp.http.after == "/foo/bar"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200214 expect resp.http.after-full == "/foo/bar"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200215
216 txreq -url "/foo/.."
217 rxresp
218 expect resp.http.before == "/foo/.."
219 expect resp.http.after == "/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200220 expect resp.http.after-full == "/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200221
222 txreq -url "/foo/../"
223 rxresp
224 expect resp.http.before == "/foo/../"
225 expect resp.http.after == "/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200226 expect resp.http.after-full == "/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200227
228 txreq -url "/foo/bar/../"
229 rxresp
230 expect resp.http.before == "/foo/bar/../"
231 expect resp.http.after == "/foo/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200232 expect resp.http.after-full == "/foo/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200233
234 txreq -url "/foo/../bar"
235 rxresp
236 expect resp.http.before == "/foo/../bar"
237 expect resp.http.after == "/bar"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200238 expect resp.http.after-full == "/bar"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200239
240 txreq -url "/foo/../bar/"
241 rxresp
242 expect resp.http.before == "/foo/../bar/"
243 expect resp.http.after == "/bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200244 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200245
246 txreq -url "/foo/../../bar/"
247 rxresp
248 expect resp.http.before == "/foo/../../bar/"
249 expect resp.http.after == "/../bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200250 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200251
252 txreq -url "/foo//../../bar/"
253 rxresp
254 expect resp.http.before == "/foo//../../bar/"
255 expect resp.http.after == "/bar/"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200256 expect resp.http.after-full == "/bar/"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200257
258 txreq -url "/foo/?bar=/foo/../"
259 rxresp
260 expect resp.http.before == "/foo/?bar=/foo/../"
261 expect resp.http.after == "/foo/?bar=/foo/../"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200262 expect resp.http.after-full == "/foo/?bar=/foo/../"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200263
264 txreq -url "/foo/../?bar=/foo/../"
265 rxresp
266 expect resp.http.before == "/foo/../?bar=/foo/../"
267 expect resp.http.after == "/?bar=/foo/../"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200268 expect resp.http.after-full == "/?bar=/foo/../"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200269
270 txreq -req OPTIONS -url "*"
271 rxresp
272 expect resp.http.before == "*"
273 expect resp.http.after == "*"
Tim Duesterhus560e1a62021-04-15 21:46:00 +0200274 expect resp.http.after-full == "*"
Tim Duesterhus9982fc22021-04-15 21:45:59 +0200275} -run
Tim Duesterhusd7b89be2021-04-15 21:46:01 +0200276
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200277client c3 -connect ${h1_fe_sort_query_by_name_sock} {
Tim Duesterhusd7b89be2021-04-15 21:46:01 +0200278 txreq -url "/?a=a"
279 rxresp
280 expect resp.http.before == "/?a=a"
281 expect resp.http.after == "/?a=a"
282
283 txreq -url "/?a=a&z=z"
284 rxresp
285 expect resp.http.before == "/?a=a&z=z"
286 expect resp.http.after == "/?a=a&z=z"
287
288 txreq -url "/?z=z&a=a"
289 rxresp
290 expect resp.http.before == "/?z=z&a=a"
291 expect resp.http.after == "/?a=a&z=z"
292
293 txreq -url "/?a=z&z=a"
294 rxresp
295 expect resp.http.before == "/?a=z&z=a"
296 expect resp.http.after == "/?a=z&z=a"
297
298 txreq -url "/?z=a&a=z"
299 rxresp
300 expect resp.http.before == "/?z=a&a=z"
301 expect resp.http.after == "/?a=z&z=a"
302
303 txreq -url "/?c&b&a&z&x&y"
304 rxresp
305 expect resp.http.before == "/?c&b&a&z&x&y"
306 expect resp.http.after == "/?a&b&c&x&y&z"
307
308 txreq -url "/?a=&aa=&aaa=&aaaa="
309 rxresp
310 expect resp.http.before == "/?a=&aa=&aaa=&aaaa="
311 expect resp.http.after == "/?a=&aa=&aaa=&aaaa="
312
313 txreq -url "/?aaaa=&a=&aa=&aaa="
314 rxresp
315 expect resp.http.before == "/?aaaa=&a=&aa=&aaa="
316 expect resp.http.after == "/?a=&aa=&aaa=&aaaa="
317
318 txreq -url "/?a=5&a=3&a=1&a=2&a=4"
319 rxresp
320 expect resp.http.before == "/?a=5&a=3&a=1&a=2&a=4"
321 expect resp.http.after == "/?a=5&a=3&a=1&a=2&a=4"
322
323 txreq -url "/?a=5&b=3&a=1&a=2&b=4"
324 rxresp
325 expect resp.http.before == "/?a=5&b=3&a=1&a=2&b=4"
326 expect resp.http.after == "/?a=5&a=1&a=2&b=3&b=4"
327
328 txreq -url "/"
329 rxresp
330 expect resp.http.before == "/"
331 expect resp.http.after == "/"
332
333 txreq -url "/?"
334 rxresp
335 expect resp.http.before == "/?"
336 expect resp.http.after == "/?"
337
338 txreq -req OPTIONS -url "*"
339 rxresp
340 expect resp.http.before == "*"
341 expect resp.http.after == "*"
342} -run
Tim Duesterhusa4071932021-04-15 21:46:02 +0200343
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200344client c4 -connect ${h1_fe_percent_to_uppercase_sock} {
Tim Duesterhusa4071932021-04-15 21:46:02 +0200345 txreq -url "/a?a=a"
346 rxresp
347 expect resp.http.before == "/a?a=a"
348 expect resp.http.after == "/a?a=a"
349
350 txreq -url "/%aa?a=%aa"
351 rxresp
352 expect resp.http.before == "/%aa?a=%aa"
353 expect resp.http.after == "/%AA?a=%AA"
354
355 txreq -url "/%zz?a=%zz"
356 rxresp
357 expect resp.status == 200
358 expect resp.http.before == "/%zz?a=%zz"
359 expect resp.http.after == "/%zz?a=%zz"
360
361 txreq -req OPTIONS -url "*"
362 rxresp
363 expect resp.http.before == "*"
364 expect resp.http.after == "*"
365} -run
366
Tim Duesterhus5be6ab22021-04-17 11:21:10 +0200367client c5 -connect ${h1_fe_percent_to_uppercase_strict_sock} {
Tim Duesterhusa4071932021-04-15 21:46:02 +0200368 txreq -url "/a?a=a"
369 rxresp
370 expect resp.http.before == "/a?a=a"
371 expect resp.http.after == "/a?a=a"
372
373 txreq -url "/%aa?a=%aa"
374 rxresp
375 expect resp.http.before == "/%aa?a=%aa"
376 expect resp.http.after == "/%AA?a=%AA"
377
378 txreq -url "/%zz?a=%zz"
379 rxresp
380 expect resp.status == 400
381} -run
Maximilian Maderff3bb8b2021-04-21 00:22:50 +0200382
383client c6 -connect ${h1_fe_dot_sock} {
384 txreq -url "/"
385 rxresp
386 expect resp.http.before == "/"
387 expect resp.http.after == "/"
388
389 txreq -url "/a/b"
390 rxresp
391 expect resp.http.before == "/a/b"
392 expect resp.http.after == "/a/b"
393
394 txreq -url "/."
395 rxresp
396 expect resp.http.before == "/."
397 expect resp.http.after == "/"
398
399 txreq -url "/./"
400 rxresp
401 expect resp.http.before == "/./"
402 expect resp.http.after == "/"
403
404 txreq -url "/a/."
405 rxresp
406 expect resp.http.before == "/a/."
407 expect resp.http.after == "/a/"
408
409 txreq -url "/a."
410 rxresp
411 expect resp.http.before == "/a."
412 expect resp.http.after == "/a."
413
414 txreq -url "/.a"
415 rxresp
416 expect resp.http.before == "/.a"
417 expect resp.http.after == "/.a"
418
419 txreq -url "/a/."
420 rxresp
421 expect resp.http.before == "/a/."
422 expect resp.http.after == "/a/"
423
424 txreq -url "/a/./"
425 rxresp
426 expect resp.http.before == "/a/./"
427 expect resp.http.after == "/a/"
428
429 txreq -url "/a/./a"
430 rxresp
431 expect resp.http.before == "/a/./a"
432 expect resp.http.after == "/a/a"
433
434 txreq -url "/a/../"
435 rxresp
436 expect resp.http.before == "/a/../"
437 expect resp.http.after == "/a/../"
438
439 txreq -url "/a/../a"
440 rxresp
441 expect resp.http.before == "/a/../a"
442 expect resp.http.after == "/a/../a"
443
444 txreq -url "/?a=/./"
445 rxresp
446 expect resp.http.before == "/?a=/./"
447 expect resp.http.after == "/?a=/./"
448} -run
Tim Duesterhus2e4a18e2021-04-21 21:20:36 +0200449
450client c7 -connect ${h1_fe_percent_decode_unreserved_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 == 200
469 expect resp.http.before == "/%%36%36"
470 expect resp.http.after == "/%66"
471
472 txreq -req OPTIONS -url "*"
473 rxresp
474 expect resp.http.before == "*"
475 expect resp.http.after == "*"
476} -run
477
478client c8 -connect ${h1_fe_percent_decode_unreserved_strict_sock} {
479 txreq -url "/a?a=a"
480 rxresp
481 expect resp.http.before == "/a?a=a"
482 expect resp.http.after == "/a?a=a"
483
484 txreq -url "/%61?%61=%61"
485 rxresp
486 expect resp.http.before == "/%61?%61=%61"
487 expect resp.http.after == "/a?a=a"
488
489 txreq -url "/%3F?foo=bar"
490 rxresp
491 expect resp.http.before == "/%3F?foo=bar"
492 expect resp.http.after == "/%3F?foo=bar"
493
494 txreq -url "/%%36%36"
495 rxresp
496 expect resp.status == 400
497} -run
Tim Duesterhusc9e05ab2021-05-10 17:28:25 +0200498
499client c9 -connect ${h1_fe_fragment_strip_sock} {
500 txreq -url "/#foo"
501 rxresp
502 expect resp.http.before == "/#foo"
503 expect resp.http.after == "/"
504
505 txreq -url "/%23foo"
506 rxresp
507 expect resp.http.before == "/%23foo"
508 expect resp.http.after == "/%23foo"
509
510 txreq -req OPTIONS -url "*"
511 rxresp
512 expect resp.http.before == "*"
513 expect resp.http.after == "*"
514} -run
Tim Duesterhusdec1c362021-05-10 17:28:26 +0200515
516client c10 -connect ${h1_fe_fragment_encode_sock} {
517 txreq -url "/#foo"
518 rxresp
519 expect resp.http.before == "/#foo"
520 expect resp.http.after == "/%23foo"
521
522 txreq -url "/#foo/#foo"
523 rxresp
524 expect resp.http.before == "/#foo/#foo"
525 expect resp.http.after == "/%23foo/%23foo"
526
527 txreq -url "/%23foo"
528 rxresp
529 expect resp.http.before == "/%23foo"
530 expect resp.http.after == "/%23foo"
531
532 txreq -req OPTIONS -url "*"
533 rxresp
534 expect resp.http.before == "*"
535 expect resp.http.after == "*"
536} -run