remote_billing: Sort out remote_billing_identities typing.

This does two important things:
1. Fix return type of get_identity_dict_from_session to correctly be
   Optional[Union[RemoteBillingIdentityDict, LegacyServerIdentityDict]].
   RemoteBillingIdentityDict is the type in the 8.0+ auth flow,
   LegacyServerIdentityDict is the type in old servers flow, where only
   the server uuid info is available.
2. The uuid key used in request.session["remote_billing_identities"]
   should be explicitly namespaced depending on which flow and type
   we're
   dealing with - to avoid confusion in case of collisions between a
   realm and server that have the same UUID. Such a situation should not
   occur naturally and I haven't come up with any actual exploitation
   ideas that could utilize this by manipulating your server/realm
   uuids, but it's much easier to just not think about such collision
   security implications by making them impossible.
This commit is contained in:
Mateusz Mandera
2023-11-30 20:47:23 +01:00
committed by Tim Abbott
parent 8370268f89
commit 5a198c639e
4 changed files with 34 additions and 21 deletions

View File

@@ -49,14 +49,11 @@ def authenticated_remote_realm_management_endpoint(
return render(request, "404.html", status=404)
realm_uuid = kwargs.get("realm_uuid")
server_uuid = kwargs.get("server_uuid")
if realm_uuid is not None and not isinstance(realm_uuid, str):
raise TypeError("realm_uuid must be a string or None")
if server_uuid is not None and not isinstance(server_uuid, str):
raise TypeError("server_uuid must be a string or None")
remote_realm = get_remote_realm_from_session(
request, realm_uuid=realm_uuid, server_uuid=server_uuid
)
remote_realm = get_remote_realm_from_session(request, realm_uuid)
billing_session = RemoteRealmBillingSession(remote_realm)
return view_func(request, billing_session)