Removal: AppDomain client search / build from AppDomain server

I have an application with the AppDomain server that accepts calls from individual AppDomains (which are host plugins developed by other people and not trustworthy).

From the AppDomain server, I need to know which “plug-in” (AppDomain) actually makes the call so that I can make sure that this plug-in has access to the resource.

I can simply pass the credentials to a call to the remote call method, but I am concerned that the cunning programmer of Plug-in A may change the code so that it appears from Plug-in B.

I considered creating my own implementation of ObjRef in a Server application, believing that "ChannelInfo.ChannelData" might contain information about the client plug-in making the call, and implemented the following code:

public int DomainId
    {
        get
        {
            int domainId = -1;

            // The type "System.Runtime.Remoting.Channels.CrossAppDomainData" is not Public,
            // so we have to use reflection to get access to it.
            for (int i = 0; i < ChannelInfo.ChannelData.Length; i++)
            {
                object o = ChannelInfo.ChannelData[i];
                if (o.ToString() == "System.Runtime.Remoting.Channels.CrossAppDomainData")
                {
                    System.Reflection.BindingFlags flags =
                        System.Reflection.BindingFlags.GetProperty
                        | System.Reflection.BindingFlags.Instance
                        | System.Reflection.BindingFlags.NonPublic;

                    domainId = (int)o.GetType().GetProperty("DomainID", flags).GetValue(o, null);
                }
            }
            return domainId;
        }
    }

But the DomainId obtained from this is the same as the AppDomain.CurrentDomain.Id servers when I really need the AppDomain Id of the client (caller)

It feels like it's too complicated :-)

Any ideas?

+3
source share
1 answer

Can you ask them to put some kind of ticket in the call context? If possible, it is easy to identify the caller and act as a result. This may not be the best solution, but it should work. We did this, and I think he is still in prod;)

0

Source: https://habr.com/ru/post/1729302/


All Articles