简体   繁体   English

防止恶意用户执行JavaScript

[英]Prevent malicious user from executing JavaScript

In my JSP I have a function like fnGetTicketDetails : 在我的JSP中,我有一个类似fnGetTicketDetails的函数:

function fnGetTicketDetails(record){
    $("#TicketNumber").val(record);
    $("#TicketDetailsForm").submit();
    return false;
}

I have form like this: 我有这样的形式:

<form name="TicketDetailsForm" id="TicketDetailsForm" method="post" action='${properties["SUBMIT_TICKET_DETAIL"]}'
    target="_blank" style="display: none;">

I have an input hidden parameter 我有一个输入隐藏参数

<input type="hidden" name="record" id="TicketNumber" /> 

It is working fine in the server. 在服务器上工作正常。 Issue was: If I use 问题是:如果我使用

javascript:eval("fnGetTicketDetails(83769551); eval();");

in the browser then also I am getting the details, which is invalid. 在浏览器中,然后我也正在获取详细信息,这是无效的。 How to block these type of request from browser. 如何阻止来自浏览器的此类请求。 Because a hacker can easily get the details if he knows the ticket number. 因为如果黑客知道票证号,便可以轻松获得详细信息。

You can't prevent the user from doing this. 您不能阻止用户这样做。

You must treat all input from the user including all requests sent by your JavaScript as untrusted. 必须将来自用户的所有输入( 包括 JavaScript发送的所有请求)视为不可信。

That means that the server must verify that the request from the user is legitimate (ie it must check if the current user has permission to read the specified detail). 这意味着服务器 必须验证来自用户的请求是否合法(即,它必须检查当前用户是否有权读取指定的详细信息)。

Relying on hidden fields and JavaScript to keep your data secure is a very easy way of getting your data stolen. 依靠隐藏字段和JavaScript来确保数据安全是一种很容易使数据被盗的方法。

You can't. 你不能 Any data stored on the client is going to be visible to the end user. 客户端上存储的所有数据将对最终用户可见。

The issue here is that your server is willing to show the details to anyone who asks for them. 这里的问题是您的服务器愿意将详细信息显示给任何要求它们的人。 Don't even try to stop the user asking. 甚至不要试图阻止用户询问。 Just do a check server side to make sure that that user is allowed to view those ticket details. 只需在服务器端进行检查,以确保允许该用户查看那些票证详细信息。 If they're not, don't deliver them! 如果不是,请不要运送它们!

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

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