@@ -939,39 +939,32 @@ def test_login_via_oidc(self) -> None:
939939 self .assertEqual (chan .code , 200 , chan .result )
940940 self .assertEqual (chan .json_body ["user_id" ], "@user1:test" )
941941
942- def test_multi_sso_redirect_to_unknown (self ) -> None :
943- """An unknown IdP should cause a 404 """
942+ def test_multi_sso_redirect_unknown_idp (self ) -> None :
943+ """An unknown IdP should cause a 400 bad request error """
944944 channel = self .make_request (
945945 "GET" ,
946946 "/_synapse/client/pick_idp?redirectUrl=http://x&idp=xyz" ,
947947 )
948- self .assertEqual (channel .code , 302 , channel .result )
949- location_headers = channel .headers .getRawHeaders ("Location" )
950- assert location_headers
951- sso_login_redirect_uri = location_headers [0 ]
952-
953- # it should redirect us to the standard login SSO redirect flow
954- self .assertEqual (
955- sso_login_redirect_uri ,
956- self .login_sso_redirect_url_builder .build_login_sso_redirect_uri (
957- idp_id = "xyz" , client_redirect_url = "http://x"
958- ),
959- )
948+ self .assertEqual (channel .code , 400 , channel .result )
960949
961- # follow the redirect
950+ def test_multi_sso_redirect_unknown_idp_as_url (self ) -> None :
951+ """
952+ An unknown IdP that looks like a URL should cause a 400 bad request error (to
953+ avoid open redirects).
954+
955+ Ideally, we'd have another test for a known IdP with a URL as the `idp_id`, but
956+ we can't configure that in our tests because the config validation on
957+ `oidc_providers` only allows a subset of characters. If we could configure
958+ `oidc_providers` with a URL as the `idp_id`, it should still be URL-encoded
959+ properly to avoid open redirections. We do have `test_url_as_idp_id_is_escaped`
960+ in the URL building tests to cover this case but is only a unit test vs
961+ something at the REST layer here that covers things end-to-end.
962+ """
962963 channel = self .make_request (
963964 "GET" ,
964- # We have to make this relative to be compatible with `make_request(...)`
965- get_relative_uri_from_absolute_uri (sso_login_redirect_uri ),
966- # We have to set the Host header to match the `public_baseurl` to avoid
967- # the extra redirect in the `SsoRedirectServlet` in order for the
968- # cookies to be visible.
969- custom_headers = [
970- ("Host" , SYNAPSE_SERVER_PUBLIC_HOSTNAME ),
971- ],
965+ "/_synapse/client/pick_idp?redirectUrl=something&idp=https://element.io/" ,
972966 )
973-
974- self .assertEqual (channel .code , 404 , channel .result )
967+ self .assertEqual (channel .code , 400 , channel .result )
975968
976969 def test_client_idp_redirect_to_unknown (self ) -> None :
977970 """If the client tries to pick an unknown IdP, return a 404"""
0 commit comments