JSON响应可被重写数组构造函数或恶意值未被JavaScript字符串转义利用.

Let's assume both of those vectors are addressed in the normal way. Google famously traps JSON response direct sourcing by prefixing all JSON with something like:

throw 1; < don't be evil' >

接下来是联合生网的睡觉.所以邪恶博士不能,使用我们讨论过的here种利用方式.通过在他的网站上放置以下内容来获取您的cookie(假设您已经登录):

<script src="http://yourbank.com/accountStatus.json"> 

As for string escaping rules, well if we're using double quotes, we need to prefix each with a backslash and each backslash with another backslash etc.

但我的问题是,如果这一切都是你做的呢?

Burp Suite (the automated security tool) detects embedded XSS attempts that are returned unHTML-escaped in a JSON response and it reports it as an XSS vulnerability. I have a report that my application contains vulnerabilities of this kind but I am not convinced. I've tried it and I can't make an exploit work.

所以我认为这是不对的.

有一个特定的 case ,IE MIME类型嗅探,我认为可能会导致一次攻击.毕竟,IE7仍然具有这样一个"特性",即嵌入在图像注释中的脚本标记被执行,而与内容类型标题无关.让我们先把这种明显愚蠢的行为放在一边.

当然,JSON将由原生JavaScript解析器(Firefox中的Window.JSON)或按照旧的默认jQuery行为由eval()解析.在这两种情况下,以下表达式都不会导致执行alert :

{"myJSON": "legit", "someParam": "12345<script>alert(1)</script>"}

我是对的还是错的?

推荐答案

作为记录,尽管我接受了答案,但对于我所问的确切的字面问题,我是对的,而且由于JSON值中存在非HTML转义但正确的JSON转义HTML,因此没有漏洞.如果在没有客户端转义的情况下将该值插入DOM中,可能会出现错误,但是Burpuite几乎不可能通过查看网络流量就知道是否会发生这种情况.

In the general case of determining what is a security vulnerability in these circumstances, it's instructive to recognise that while it may not feel like good design, the response content of a JSON value could legitimately be known to certainly contain no user input and be intended to be already rendered HTML to be safely inserted in the DOM unescaped. Escaping it would be a (non-security) bug as I mentioned in another comment.

Json相关问答推荐

JOLT将对象名作为新属性添加到主体中

使用Jolt将字符串数组转换为JSON对象数组

如何使用JQ将JSON字符串替换为解析后的类似功能?

如何在Vega中使标记的符号在鼠标指针悬停时可点击

使用JQ从jsonl文件中删除具有匹配键/值的行

在Zig中解析JSON失败

XSLT 3.0 Json-to-xml,json 包含 html struct

未知的META规范,无法验证.[规范v1.0.1]

基于JQ中另一个对象的值 Select 对象

修改 boost::json::object 中的值

我如何将 JSON 格式与 flutter 一起使用?帮助使用 Gamebanana api

如何在 Flutter 中遍历嵌套的动态 JSON 文件

如何迭代、动态加载我的表单输入元素,然后在 React 中的表单提交上检索输入值?

提交后使用 Rails 7 结合 JSON 标签进行标记

流导入错误:重新上传时不存在布局释放 UUID

如何使用 gson 将数据保存在 json 文件中?

JSON.stringify 不会转义?

Sequelize - 如何仅返回数据库结果的 JSON 对象?

使用适用于 Python 的 Google API - 我从哪里获取 client_secrets.json 文件?

如何使用 Javascript 将数据写入 JSON 文件