What are the best practices to secure a web API?

I need to build a web service API for our mobile app to interact with our server & database (in ASP.Net MVC 4, but that’s hardly relevant). Wile most actions do not need users to be registered with our service, we would like to restrict access only to users of our app.

What are the methods to make sure that calls made from somewhere else (e.g. someone wanting all our data, or building an unofficial app) are rejected?

My initial idea is for the device to ask the server for a token, which is randomly generated and sent as is. All other methods will check that the request headers contain a specific one that will be md5 hash of the salted token. The server knows the token and salt and is able to compute the hash and compares it with the one sent. In addition, the token as a limited lifespan, and the device must get another one every other hour.

That seems quite easy to implement and although probably not 100% proof, that seems to be a good idea. What do you think?

As soon as you release the application, it might be reverse engineered. This means that there is nothing you can do to be 100% protected if the same application (same binaries, same settings) is distributed to all of your users.

If you can customize the application for every user, then you have a chance to maybe not forbid some other application to use your API, but at least limit this application by number of requests it can do to the API.

Imagine the following schema:

  1. Client connects and sends its unique identifier (one identifier by user).
  2. Server replies by sending a challenge encrypted with a public key. This public key is associated with the unique identifier previously sent.
  3. Client solves the challenge by decrypting the data using a private key and sends the decrypted secret in plain back to the server.
  4. Server verifies that the submitted secret corresponds to the one originally generated.

The developer who will hack your application and successfully obtain the private key would be able to use your API from his own application, but he will be identifier as himself for your server.

If the same user can do 10 000 requests to your API per day and in average, an active user makes 2 000 requests per day, it means that this developer would be able to use his application himself and maybe give it to his friends, but he wouldn’t be able to, say, sell it to thousands of people, just because it will work only for a few minutes in the morning.

While this helps, it’s not 100% proof neither. What if the hacker finds a way to extract the private key from your app when his own app is installed on the device?


Side note which doesn’t answer your question, but still might be useful: don’t think about an API as a tool for your primary product (mobile application). Think about it as a first class product itself, a product which may be paid. The same model is used for years by Amazon and Google, it starts to be actively used by Microsoft with Azure, etc.

As soon as you consider the API not as a secondary tool reduced to slavery for your shiny new mobile apps, but the actual product, at the same level as any application the user actually sees, you start thinking less about how to protect the API against the usage by other apps, and more about the monetization of the API itself. Such API can be used by your apps which are its customers, or any other apps, freely developed by anyone. This has several benefits:

  • Making an API so that it would be used only by your applications is difficult and expensive. This time and money can be used for something more useful.

  • Opening your API to the public can have a great benefit for both you and the world. Imagine you’re a great architect and a great developer, so you’ve created an astonishingly great API, but your visual designer skills suck and you really don’t understand anything about interaction design, etc. If you hide your API, the only thing people will know is that you’ve created a mobile application which is unusable and ugly. If your API is public, other developers will be attracted by its quality and write great applications for it, bringing you lots of money.

  • You never imagine how other people may use your APIs. This is what happened with Kinect. Originally, Microsoft created Kinect for games. When Microsoft opened the API to the public, they never imagined it would be used a few years later by scientific applications, health sector, etc. It’s similar for web APIs: more developers are using it, more widespread the ideas would be.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật