将 JsonRequestBehavior 设置为 AllowGet 时可以披露哪些“敏感信息"

编程入门 行业动态 更新时间:2024-10-25 09:40:49
本文介绍了将 JsonRequestBehavior 设置为 AllowGet 时可以披露哪些“敏感信息"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我 返回 Json(使用内置的MVC JsonResult helper):

I've been getting the same old error every time I test a new URL from my browser's address bar when I'm returning Json (using the built-in MVC JsonResult helper):

此请求已被阻止,因为在 GET 请求 中使用此请求时,敏感信息可能会泄露给第三方网站.要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet.

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.

这一次,我不是咕哝着确认并启动 Fiddler 来执行发布请求,而是想知道 GET 请求公开了 POST 到底是什么> 请求没有?

Rather than grunt in acknowledgement and fire up Fiddler to do a post request, this time, I'm wondering exactly what it is that a GET request exposes that a POST request doesn't?

推荐答案

假设你的网站有一个 GetUser 网络方法:

Say your website has a GetUser web method:

www.example/User/GetUser/32

返回一个 JSON 响应:

which returns a JSON response:

{ "Name": "John Doe" }

如果此方法只接受 POST 请求,那么只有向 www.example/User/GetUser/32 发出 AJAX 请求时,内容才会返回给浏览器使用 POST 方法.请注意,除非您已实施 CORS,否则浏览器将保护来自向您提出此请求的其他域的数据.

If this method accepts only POST requests, then the content will only be returned to the browser if an AJAX request is made to www.example/User/GetUser/32 using the POST method. Note that unless you have implemented CORS, the browser will protect the data from other domains making this request to yours.

但是,如果您允许 GET 请求,并且使用 GET 而不是 POST 发出类似于上述的 AJAX 请求,恶意用户可能会使用 脚本将您的 JSON 包含在他们自己站点的上下文中 标签.例如在 www.evil 上:

However, if you allowed GET requests then as well as making an AJAX request similar to the above with GET instead of POST, a malicious user could include your JSON in the context of their own site by using a script tag in the HTML. e.g. on www.evil:

<script src="www.example/User/GetUser/32"></script>

这个 JavaScript 应该对 www.evil 没用,因为应该没有办法读取你的 web 方法返回的对象.但是,由于旧版本浏览器(例如 Firefox 3)的错误,JavaScript 原型对象有可能被重新定义,并使得 www.evil 可以读取您的浏览器返回的数据.方法.这称为 JSON 劫持.

This JavaScript should be useless to www.evil because there should be no way of reading the object returned by your web method. However, due to bugs in old versions of browsers (e.g. Firefox 3), it is possible for JavaScript prototype objects to be redefined and make it possible for www.evil to read your data returned by your method. This is known as JSON Hijacking.

请参阅这篇博文,了解一些防止这种情况发生的方法.但是,这不是现代浏览器(Firefox、Chrome、IE)的更高版本的已知问题.

See this post for some methods of preventing this. However, it is not a known problem with the later versions of modern browsers (Firefox, Chrome, IE).

更多推荐

将 JsonRequestBehavior 设置为 AllowGet 时可以披露哪些“敏感信息"

本文发布于:2023-10-22 08:33:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   敏感   信息   JsonRequestBehavior   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!