简体   繁体   English

通过PHP中的AJAX获取或传递敏感数据

[英]Get or Pass Sensitive Data via AJAX in PHP

I want to update a row of data in a database using Ajax and PHP; 我想使用Ajax和PHP更新数据库中的一行数据; however, I'm struggling with the following issue: the field in the database to update (henceforth the id ) is dependent on the page the ajax request is sent from . 但是,我在以下问题上苦苦挣扎: 要更新的数据库中的字段(此后为id )取决于ajax请求从其发送的页面

I need to get this id to my PHP script that Ajax calls, however: 但是,我需要将此id放入Ajax调用的PHP脚本中:

  1. I don't want to set the id in a data attribute or hidden input on the page because these can both be manipulated by a malicious user. 我不想在页面的数据属性或隐藏输入中设置id ,因为它们都可以被恶意用户操纵。

  2. Similarly, identifying the id using the referring URL is also prone to spoofing as $_SERVER isn't secure. 同样,使用$_SERVER URL标识也不安全,因此使用引用URL标识id也容易受到欺骗。

  3. I can't set the id in a SESSION variable (or COOKIES) because the user could have multiple pages open and the SESSION would only hold the last page id that was opened. 我无法在SESSION变量(或COOKIES)中设置id ,因为用户可能会打开多个页面,并且SESSION将仅保留打开的最后一个页面id

The only solution I can think is to create a map of random tokens to id 's in a table in the db and pass that in a SESSION variable (as per #3 above), then check the table for the token and grab the respective id that way. 我能想到的唯一解决方案是在db表中创建一个随机令牌到id的映射,并将其传递到SESSION变量中(按照上述#3),然后检查该表中的令牌并获取相应的令牌id的方式。 Seems somewhat convoluted though. 似乎有些令人费解。

Are there any other options or thoughts? 还有其他选择或想法吗? Thanks. 谢谢。

This is a problem related to OWASP Top10 A7 (Missing Function Level Access Control). 这是与OWASP Top10 A7 (缺少功能级别访问控制)有关的问题。

There might be no issue with putting your ID on the page so the page can send it back - you just need to validate that the actual save request is permitted for the user. 将您的ID放在页面上可能没有问题,因此页面可以将其发送回-您只需要验证用户是否允许实际的保存请求即可。

Just think, regardless of whether you put the ID on the page or not, the page does know the base url for performing the action, so they could go ahead and guess IDs anyway. 试想一下,无论是否在页面上放置ID,页面都知道执行该操作的基本URL,因此他们可以继续猜测ID。

Simplify your logic. 简化您的逻辑。 Pass some sort of indicator of what type of id is in use from the client to the server. 从客户端到服务器传递某种指示符,以指示正在使用哪种类型的ID。

If you create overly complex application logic to address a security concern you will probably have more problems with your code than improvements in security. 如果您创建过于复杂的应用程序逻辑来解决安全性问题,则代码的问题可能会比安全性方面的改进更多。

Use SSL/HTTPS and a WAF (web application firewall - like mod_security). 使用SSL / HTTPS和WAF(Web应用程序防火墙-如mod_security)。

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

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