|
416 | 416 | :get "/slash-less//" "/slash-less?kikka=kukka" |
417 | 417 | :post "/with-slash" "/with-slash/?kikka=kukka" |
418 | 418 | :post "/slash-less/" "/slash-less?kikka=kukka" |
419 | | - :post "/slash-less//" "/slash-less?kikka=kukka")))))) |
| 419 | + :post "/slash-less//" "/slash-less?kikka=kukka")))) |
| 420 | + |
| 421 | + ;; See issue #337 |
| 422 | + (testing "Avoid external redirects" |
| 423 | + (let [app (ring/ring-handler |
| 424 | + (ring/router [["*" {:get (constantly nil)}]]) |
| 425 | + (ring/redirect-trailing-slash-handler)) |
| 426 | + resp (fn [uri & [query-string]] |
| 427 | + (let [r (app {:request-method :get :uri uri :query-string query-string})] |
| 428 | + {:status (:status r) |
| 429 | + :Location (get-in r [:headers "Location"])}))] |
| 430 | + (testing "without query params" |
| 431 | + (is (= {:status 301 :Location "/malicious.com/foo/"} (resp "//malicious.com/foo"))) |
| 432 | + (is (= {:status 301 :Location "/malicious.com/foo"} (resp "//malicious.com/foo/"))) |
| 433 | + (is (= {:status 301 :Location "/malicious.com/foo"} (resp "//malicious.com/foo//"))) |
| 434 | + (is (= {:status 301 :Location "/malicious.com/foo/"} (resp "///malicious.com/foo"))) |
| 435 | + (is (= {:status 301 :Location "/malicious.com/foo"} (resp "///malicious.com/foo/"))) |
| 436 | + (is (= {:status 301 :Location "/malicious.com/foo"} (resp "///malicious.com/foo//")))) |
| 437 | + (testing "with query params" |
| 438 | + (is (= {:status 301 :Location "/malicious.com/foo/?bar=quux"} (resp "//malicious.com/foo" "bar=quux"))) |
| 439 | + (is (= {:status 301 :Location "/malicious.com/foo?bar=quux"} (resp "//malicious.com/foo/" "bar=quux"))) |
| 440 | + (is (= {:status 301 :Location "/malicious.com/foo?bar=quux"} (resp "//malicious.com/foo//" "bar=quux"))) |
| 441 | + (is (= {:status 301 :Location "/malicious.com/foo/?bar=quux"} (resp "///malicious.com/foo" "bar=quux"))) |
| 442 | + (is (= {:status 301 :Location "/malicious.com/foo?bar=quux"} (resp "///malicious.com/foo/" "bar=quux"))) |
| 443 | + (is (= {:status 301 :Location "/malicious.com/foo?bar=quux"} (resp "///malicious.com/foo//" "bar=quux")))))))) |
420 | 444 |
|
421 | 445 | (deftest async-ring-test |
422 | 446 | (let [promise #(let [value (atom ::nil)] |
|
0 commit comments