简体   繁体   English

如何执行<script> tag coming in AJAX call, without making any change in client side JS

[英]How to to execute <script> tag coming in AJAX call, without making any change in client side JS

[
    {
        "Book ID": "1",
        "Book Name": "UNIX **<script type='text/javascript'>alert('test')</script>**",
        "Category": "Computers",
        "Price": "113"
    }, 
    {
        "Book ID": "2",
        "Book Name": "Book two",
        "Category": "Programming",
        "Price": "562"
    }
]

This is the JSON I am sending via API I am sharing with multiple people. 这是我通过API发送的JSON,我与多个人共享。 When I parse the JSON using JavaScript, <script> tag is not executed. 当我使用JavaScript解析JSON时,不会执行<script>标记。 What are the modification should I make in the JS injected into JSON so that <script> tag will be executed without doing any extra work at client side JS. 我应该对注入JSON的JS进行哪些修改,以便在不对客户端JS进行任何额外工作的情况下执行<script>标记。 Is it possible? 可能吗?

It is not possible. 这不可能。

If the techniques you are using to insert that code into the document do not trigger the JS, than changing what you are inserting won't fix that. 如果您用于将代码插入文档中的技术没有触发JS,那么更改您要插入的内容将无法解决该问题。

You have two options: 您有两种选择:

Find a flaw in the client page and exploit it, for example, if the client js get's the API answer and prints it in a <label> tag unsanitized, you could send something like </label><script>alert(1)</script><label> so your script would close the label, inject your script and open it again. 在客户端页面中找到一个漏洞并加以利用,例如,如果客户端js得到了API答案并在未经过消毒的<label>标签中打印出来,则可以发送</label><script>alert(1)</script><label>因此您的脚本将关闭标签,注入脚本并再次将其打开。

Or you could do a minimal modification in clientside and get the object from API as this: 或者,您可以在客户端进行最少的修改,然后从API获取对象,如下所示:

{
    "Book ID": "1",
    "Book Name": "UNIX",
    "script": "alert('test')",
    "Category": "Computers",
    "Price": "113"
},

And then, in clientside run it with: 然后,在客户端运行:

Function(obj.script)();

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

相关问题 进行Ajax调用时如何尊重客户端验证 - How to respect client side validation when making an ajax call 在非ajax调用中在客户端执行JavaScript - Execute JavaScript on client side within an non ajax call 在js中执行脚本标签 - Execute script tag in js 从客户端 JavaScript AJAX 调用 WebAPI GET 方法,得到错误 - Making a call to a WebAPI GET method from client side JavaScript AJAX, getting error 有没有办法尝试/捕获来自给定的任何JS噪声<script> tag - Is there a way to try/catch any JS noise coming from a given <script> tag 如何从Node JS客户端调用Node JS函数 - How to call node js function from node js client side 如何在Ajax响应返回的脚本标签内执行javascript - How to execute javascript inside a script tag returned by an ajax response 首先调用服务器端代码,然后调用客户端脚本,而无需使用AJAX - first invoke server side code then client side script without using AJAX JSPM-使用import和使用script标签来包含客户端库文件是否有优点/缺点? - JSPM - Are there any advantages/disadvantages in including client side library files using import vs using the script tag? 如何使用任何客户端脚本或服务器端脚本在Calender Extender中禁用上一个日期 - How to Disable Previous Date in Calender Extender Using any client Side Script OR Server Side Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM