开发者

Securing REST calls made by JavaScript from an unsecured page

开发者 https://www.devze.com 2023-04-01 19:47 出处:网络
We have a web-based application in which we are not requiring end users to login. The application uses Ajax to make calls to REST services hosted on the same server. Besides this application, we want

We have a web-based application in which we are not requiring end users to login. The application uses Ajax to make calls to REST services hosted on the same server. Besides this application, we want to make sure that if any other applications / agents call the REST service they get denied.

What is the simplest way to secure a REST API like this? My guess is that we would include some sort of security token and make the call through HTTPS. However I'm not clear how the Ajax application would create/obtain/encrypt the token and generally what the lifecyc开发者_StackOverflow中文版le looks like.

I would rather do this outside of Spring Security or OAuth if possible. I have also read that sending username and password over SSL is enough for authentication. In this case, the app would have a "username" and password and it would send it with every request to the REST service. But how would it keep that information secret if the client is just HTML and javascript in the browser?

Thanks.


In general this is impossible. Someone could just do view source on your javascript, read the token, then do whatever they want.

https is not necessary here. For the token, probably the easiest is to set a cookie when they download the javascript from the server, then that cookie will also be transmitted with any AJAX requests.

This is not really secure - anyone can just see what the cookie is and use it, but it's the best you can do.

0

精彩评论

暂无评论...
验证码 换一张
取 消