<bdo id='Pa1WX'></bdo><ul id='Pa1WX'></ul>

  1. <legend id='Pa1WX'><style id='Pa1WX'><dir id='Pa1WX'><q id='Pa1WX'></q></dir></style></legend>
    1. <tfoot id='Pa1WX'></tfoot>
      <i id='Pa1WX'><tr id='Pa1WX'><dt id='Pa1WX'><q id='Pa1WX'><span id='Pa1WX'><b id='Pa1WX'><form id='Pa1WX'><ins id='Pa1WX'></ins><ul id='Pa1WX'></ul><sub id='Pa1WX'></sub></form><legend id='Pa1WX'></legend><bdo id='Pa1WX'><pre id='Pa1WX'><center id='Pa1WX'></center></pre></bdo></b><th id='Pa1WX'></th></span></q></dt></tr></i><div id='Pa1WX'><tfoot id='Pa1WX'></tfoot><dl id='Pa1WX'><fieldset id='Pa1WX'></fieldset></dl></div>

      <small id='Pa1WX'></small><noframes id='Pa1WX'>

      保护ajax请求完整性的最佳方法

      时间:2023-06-23

    2. <tfoot id='8yx8o'></tfoot>

        <legend id='8yx8o'><style id='8yx8o'><dir id='8yx8o'><q id='8yx8o'></q></dir></style></legend>
      1. <i id='8yx8o'><tr id='8yx8o'><dt id='8yx8o'><q id='8yx8o'><span id='8yx8o'><b id='8yx8o'><form id='8yx8o'><ins id='8yx8o'></ins><ul id='8yx8o'></ul><sub id='8yx8o'></sub></form><legend id='8yx8o'></legend><bdo id='8yx8o'><pre id='8yx8o'><center id='8yx8o'></center></pre></bdo></b><th id='8yx8o'></th></span></q></dt></tr></i><div id='8yx8o'><tfoot id='8yx8o'></tfoot><dl id='8yx8o'><fieldset id='8yx8o'></fieldset></dl></div>

          <bdo id='8yx8o'></bdo><ul id='8yx8o'></ul>
              • <small id='8yx8o'></small><noframes id='8yx8o'>

                  <tbody id='8yx8o'></tbody>
              • 本文介绍了保护ajax请求完整性的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在构建一个 Drupal 网站,其中包含大量用户特定的信息,这些信息将使用 jQuery/ajax 发布.信息本身不是很敏感,重要的是要验证表单数据没有被 Firebug 等工具篡改,以及确保信息确实是从指定用户那里请求的.换句话说,我试图找出在使用 ajax 发布时保护数据完整性和真实性的最佳方法.

                I am building a Drupal website with a lot of user-specific information that will be posted using jQuery/ajax. The information it self is not very sensitive, it is just important to verify that the form-data has not been tampered with tools like Firebug, as well as ensuring the information is really requested from the specified user. In other words, I am trying to figure out the best way to protect the integrity and authenticity of the data when posting with ajax.

                理想情况下,我想使用一些众所周知的消息认证系统,比如 HMAC 算法.但由于这包含了一个对称密钥,我不知道如何加密 POST 数据而不暴露我的 javascript 文件中的密钥(显然任何人都可以看到).

                Ideally I would like to use some well known message authentication system, like the HMAC algorithm. But since this incorporates a symmetric key, I don't see how I can encrypt the POST data without exposing the secret key in my javascript file (which obviously is visible to anyone).

                如果我对这应该如何工作有错误的想法,请纠正我.

                Please correct me if I have got the wrong idea about how this should work.

                例如,我需要发送的信息

                For example, info I need to send

                field1=x&field2=y&uid=10
                

                ...然后计算数据的哈希值和密钥.这是否可以在不公开我的 javascript 代码中的哈希函数的情况下完成?

                ...then calculate the hash of the data together with a secret key. Is this possible to do without exposing the hash function in my javascript code?

                CHECKSUM: hash(postdata, "secret_key")
                

                ... 最后将校验和附加到原始 postdata.

                ... and finally append checksum to original postdata.

                field1=x&field2=y&uid=1&c=CHECKSUM
                

                替代方案

                我想到的另一种方法是使用登录用户的会话 ID.但是,这不会检查消息的完整性...

                Alternative

                An alternative I though of was using the session ID of the logged in user. This however would not check the integrity of the message...

                使用 PHP 生成表单时,我可以使用以下内容生成隐藏输入

                When generating form with PHP, I can generate a hidden input with following

                CHECKSUM: hash(session id for the current user, "secretkey")
                

                然后我会使用 ajax 发布的是

                What I then would post using ajax is

                field1=x&field2=y&uid=10&c=CHECKSUM
                

                有了这个,验证适当的用户(再次伪代码)将是相当安全的

                With this it would be fairly secure to authenticate the appropriate user (again pseudo-code)

                ssid = SELECT ssid FROM sessions WHERE uid = $_POST[uid]
                if(ssid && hash(ssid, "secretkey") == $_POST[c]) {
                     //User OK
                } else {
                     //Invalid user
                }
                

                推荐答案

                你不能做你想做的事.基本上,您试图验证不受信任和不受控制的客户端上的一个组件(您的表单)没有被同一客户端上的另一个组件篡改.您无法控制客户端.您可以想出各种方法来使某人更难在他们的客户端上执行此操作,但最终您必须向客户端公开您如何进行这些完整性检查.无论您在表单脚本中做什么,该客户端上的人都可以阅读和理解(它必须在客户端上运行,因此与客户端交互的任何人都可以对您正在做的任何事情进行逆向工程以恢复所使用的技术和任何密钥/etc 您必须启用您的方案).

                You cannot do what you're trying to do. Basically, you're trying to verify that one component (your form) on an untrusted and uncontrolled client is not tampered with by another component on that same client. You don't control the client. You can come up with all sorts of methods to make it harder for someone to do this on their client, but in the end you must expose how you're doing those integrity checks to the client. Whatever you do in your form scripts can be read and understood by the person on that client (it has to run on the client, so whomever is interacting with the client can reverse engineer anything you're doing to recover the techniques used and any keys/etc that you have to enable your scheme).

                Web 应用程序安全的基本规则是您无法控制客户端上发生的事情,因此您不能信任像这样的客户端验证/安全方案.

                Basic rule of web application security is that you cannot control what's happening on the client, so you cannot trust client-side verification/security schemes like this.

                最终,这种计划提供的保护不太可能值得花时间和投资来实施.决心打破它的人将能够做到.

                In the end, it's unlikely that the protection offered by such a scheme would be worth the time and investment to implement it. Someone who is determined to break it will be able to.

                这篇关于保护ajax请求完整性的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何通过 PHP 在页面正文中获取 URL 参数? 下一篇:致命错误:第 551 行的 c:wampwwwdrupal2includescommon.inc 中超出了 30 秒的最

                相关文章

              • <tfoot id='tbiI7'></tfoot>
                  <bdo id='tbiI7'></bdo><ul id='tbiI7'></ul>

                <legend id='tbiI7'><style id='tbiI7'><dir id='tbiI7'><q id='tbiI7'></q></dir></style></legend>

                <small id='tbiI7'></small><noframes id='tbiI7'>

                  1. <i id='tbiI7'><tr id='tbiI7'><dt id='tbiI7'><q id='tbiI7'><span id='tbiI7'><b id='tbiI7'><form id='tbiI7'><ins id='tbiI7'></ins><ul id='tbiI7'></ul><sub id='tbiI7'></sub></form><legend id='tbiI7'></legend><bdo id='tbiI7'><pre id='tbiI7'><center id='tbiI7'></center></pre></bdo></b><th id='tbiI7'></th></span></q></dt></tr></i><div id='tbiI7'><tfoot id='tbiI7'></tfoot><dl id='tbiI7'><fieldset id='tbiI7'></fieldset></dl></div>