简体   繁体   English

MVC 4 Web Api 安全性

[英]MVC 4 Web Api Security

I am very new in web api security.我在 web api 安全方面很新。 I have used form authentication technique.我使用了表单身份验证技术。 when user logs in, a token is created and stored as a cookie in user's web browser.当用户登录时,会创建一个令牌并将其作为 cookie 存储在用户的 Web 浏览器中。 On each request the token is varified and if user is authenticated and authorized user is given access to the service.在每个请求中,令牌都会改变,如果用户经过身份验证并且授权用户可以访问服务。

but I think this approach does nothing in web api security.但我认为这种方法在 web api 安全性方面没有任何作用。 cookies can easily be copied and pasted in other browser and anyone can get the service. cookie 可以很容易地复制并粘贴到其他浏览器中,任何人都可以获得该服务。

I am thinking to use App key and secret along with form authentication.我正在考虑将 App 密钥和机密与表单身份验证一起使用。 I am not suggested to use third party service like Oauth for authentication.我不建议使用 Oauth 等第三方服务进行身份验证。 I am not Sure about the Implementation of app key and secret that how it exactly works.我不确定应用程序密钥和秘密的实现究竟是如何工作的。

Please provide better way to secure my web api wihtout using third party services and to prevent cookie hijacking etc. What actions are performed to build a strengthly secure web api.请提供更好的方法来保护我的 web api 而不使用第三方服务并防止 cookie 劫持等。执行哪些操作来构建一个非常安全的 web api。

The forms authentication is good enough.表单身份验证已经足够好了。 You can also do the following:您还可以执行以下操作:

  1. Use anti-forgery (antifrogery) tokens.使用防伪(antifrogery)令牌。 Check this or this检查这个这个
  2. It will also be great if on sensitive actions you check if the call to the function was made from the same site or not.You can implement your own action filter for this.如果在敏感操作中检查对函数的调用是否来自同一站点,这也会很棒。您可以为此实现自己的操作过滤器。 (check if the referral site is your site, or the expected site) (检查推荐网站是您的网站还是预期的网站)

Edited:编辑:

Thanks guys for your comments.谢谢你们的评论。 I guess you are right.我想你是对的。 Well authentication cookies in ASP are created as httpOnly cookies which means even if the site had some XSS vulnerabilities it will still be safe and cant be stolen. ASP 中的身份验证 cookie 被创建为 httpOnly cookie,这意味着即使该站点存在一些 XSS 漏洞,它仍然是安全的并且不会被盗。 I would also suggest to use https everywhere if the site is used for sensitive operations (like a bank) to make sure the cookies are perfectly safe.如果站点用于敏感操作(如银行),我还建议在任何地方使用 https,以确保 cookie 完全安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM