I'm working on a REST API built with WCF WebApi Preview 6. This is for a multi-tenant application and consumed by different clients (web and mobile applications).
There are certain resources on this API that requires authentication in order to access them or operate with them. The information to the API for those endpoints is provided by the client by using a encrypted token, containing encrypted information about the device, user, tenant, etc.
I created a stress test which is actually revealing data leakage across tenants. I'm going to explain one concrete example and the workflow in place, so you have a better idea.
A user in client device authenticates with the API and get a token. Later on, the device POST a resource to an endpoint that requires the security token to operate. The token validation happens in a MessageHandler, which ensures everything is fine and then put transient information in HttpCurrent.Items so it is available to the rest of the request.
We use HttpContext.Current.Items because we were sure it is scoped to the request, so later on when processing the request I could refer to the right tenant and insert the information there.
We are not sure what is happening, but some data is routed to the wrong tenant based on the information in HttpContext.Current.Items.
How can this happen?
Is the information in HttpContext.Current.Items stepped on before the request finishes? Is the process that handles the data actually outside the request?