gpt4 book ai didi

node.js - 保护 POST 请求

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:03 26 4
gpt4 key购买 nike

我有一个expressjs应用程序

如何在发布表单时确保 ID 的安全。

我的表单中有一个隐藏字段 ID:

<input type="text" name="id" id="id" hidden="hidden" value="1">

可以轻松更改 ID 以将无效数据发布到我的数据库。

我怎样才能保证它的安全?我应该散列它吗?

最佳答案

我能想到的唯一方法是使用可逆加密方法加密该值(散列不起作用,因为它是不可逆的)。然后,当您在服务器上收到返回的加密 ID 时,将其解密以获取值。

但是,我不建议这样做,仅仅为了防止某人在回发时更改 ID 而进行如此麻烦的操作是没有意义的。您的表单中可能还有数十个其他字段,您如何保证所有这些字段的安全?

建议您在收到回发数据时进行适当的验证,例如:

If User A is trying to edit his Profile ID 1234, the form will have a hidden field of ID 1234, when the user completes the edit operation and post the data back to the server, validate that User A has the rights to edit the posted Profile ID, if he has the right to do so, it doesn't matter if he change the ID to something else other than the original value.

关于node.js - 保护 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27658083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com