Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Uniquely Identifies a Client Making a Request to Web API?

Let's say I write a piece of code that makes an http call to a web api, something like:

$http.get('www.myapi.com/api/controller/endpoint').then(function(resp){...})

I then give this code to two people that live in different cities and they hit my API from their respective houses (just from some browser). What information can my API get out of the http request that will allow me to tell apart person A and person B calling it? Is the IP always available? Is the MAC address ever available? What else is there?

How can person A pretend to be person B when calling my API?

Furthermore, what if person C calls my Web API from their own Web API (backend)? Will the same information be available, or what will be different?

This is a general question, but if you want to get specific, let's assume ASP.NET Web API 2 is receiving the http requests.

like image 744
VSO Avatar asked Jul 28 '16 18:07

VSO


People also ask

What is the client ID in Web API?

The id read-only property of the Client interface returns the universally unique identifier of the Client object.

What is request in Web API?

Web API converts request data into CLR object and also serialize CLR object into response data based on Accept and Content-Type headers. Web API includes built-in support for JSON, XML, BSON, and form-urlencoded data. It means it automatically converts request/response data into these formats OOB (out-of the box).

How can I ensure my API is only called by my client?

If you want to restrict usage and make it inconvenient for abusers to call your API, you can issue a token on page load (CSRF token) and require that token to be present in the request to the API - that way the API will be callable from a browser that initiated a page load.


2 Answers

You're describing a desire for pre-authentication.

The IP will always be available. You could restrict the service to only those IP ranges. It's not a good way to do authentication.

Trying to get around having to perform authentication is not safe. You should use a proper authentication method. Combining IP restrictions with other methods is fine.

John Meyer's answer is essentially pre-shared token based user authentication. Having a valid token constitutes being constantly logged in. The token can be compromised far more easily than a typical token based user authentication that establishes a temporary token with a limited lifetime.

If you decide to go the pre-shared token route, please use a method that supports proper rotation or permutation of the token over time, such that it isn't vulnerable to replay attacks.

Your best option for this scenario is typical session-token based user authentication.

If you're actually not interested in who is using your service, only that they be uniquely identified, you can safely establish a session (or permanent, or arbitrary lifetime) cookie per user by the http Set-Cookie header that all clients should automatically respect and support, then use that as your method of tracking.

like image 170
TylerY86 Avatar answered Oct 05 '22 23:10

TylerY86


My team has accomplished this by requiring that an identification header be included on all requests. This does require some customization on the part of the calling party, but does not necessarily require that the user be logged in. Of course, the value of the header could be change by malicious users so if these calls need to be very secure you will need traditional authentication.

like image 43
John Meyer Avatar answered Oct 05 '22 23:10

John Meyer