Zend form:编辑时存储条目ID的安全方式?

发布于 2024-12-03 04:18:05 字数 227 浏览 1 评论 0原文

我是 Zend Framework 的新手,在使用 Zend_Form 创建编辑表单时遇到问题。

我的问题是我需要在编辑过程中存储条目 ID,我见过一些使用隐藏表单字段的示例,但隐藏字段可以由用户操作。

那么:如何设置一个由 $form->populate($data); 填充的表单字段,并且在提交请求后可用,但用户无法以任何方式编辑/可见?

感谢您的帮助!

I'm new to the Zend Framework and I have a problem to create an edit form with the Zend_Form.

My problem is that I need to store the entry ID during editing, I've seen some examples that are using a hidden form field, but a hidden field can be manipulated by a user.

So: how can I set a form field which gets populated by $form->populate($data); and is available after submiting the request but is not editabel/visible to the user in any way?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

匿名。 2024-12-10 04:18:05

我不确定试图隐藏该值是否真的有意义。

请考虑以下事项:

  • 要显示正确的编辑器表单,您需要要编辑的对象的 ID。
  • 在允许用户编辑某个 ID 之前,您需要检查用户是否可以编辑它。

因此,如果您将 ID 放入表单中,那么实际上并不重要:

  • 当您发布编辑表单时,您应该再次检查用户是否仍然可以编辑 ID。
  • 如果用户更改隐藏 ID,那也并不重要。他们仍然可以通过在网站上找到另一个 ID 来编辑它。 (这是假设您的检查没有告诉您用户没有访问权限)

I'm not sure if there's really a point in trying to hide the value.

Consider the following:

  • To display the correct editor form, you need the ID of the object that is to be edited.
  • Before allowing the user to edit a certain ID, you would check if the user can edit it or not.

Thus, if you put the ID in the form, it shouldn't really matter:

  • When you POST the edit form, you should again check that the user can still edit the ID.
  • If the user changes the hidden ID, it doesn't really matter. They could still go and edit the other ID by finding it on the site. (This is assuming your check didn't tell you the user does not have access)
舞袖。长 2024-12-10 04:18:05

你想隐藏什么样的数据?
数据应该在 post 或 get 中。如果您不将数据放入表单中,那么您将不得不使用 GET,它的安全性不如 POST。
如果您有一些数据并且不希望用户看到这些数据,那么您不应该将这些数据放入表单中。您可以使用表单提交的值存储和检索隐藏数据。假设您的隐藏字段是用户的密码。当客户端编辑表单时,您不需要将密码发送回客户端。您可以根据用户提交的名字和姓氏在控制器中操作密码。
如果您仍然坚持,您可能想尝试使用 ZF 加密数据并回显您的值并将加密数据设置到隐藏的表单元素中。

what kind of data you wanna hide?
data should be in post or get.if you dont put your data in your form,then you will have to use GET which is less secure than POST.
If you have some data and you dont want the user to see those data,then you should not put those data in a form.you can store and retrieve hidden data using forms submitted values.lets suppose your hidden field is users password.you dont need to send password back to the client when client is editing the form.you can manipulate password in your controller according to the user`s submitted first name and last name.
If you still insist, you may wanna try encrypting data using ZF and echo ing your value and setting encrypted data into a hidden form element.

握住你手 2024-12-10 04:18:05

Zend_Form 使用您指定的表单元素生成一个 HTML 表单元素。因此它的元素功能被缩小为简单的 HTML 形式。

隐藏的表单元素用于传递用户不应该手动输入的数据。但正如您自己所说,不能保证它不会被篡改。因此使用隐藏的表单值并不能提供安全性。

大多数时候,您最好使用服务器端值(例如存储在会话中)来引用要防止用户访问的值。

我建议您将 ID 保留在会话值中,然后您可以在隐藏表单字段中使用会话密钥。这样用户就无法更改目标ID。但是,您无法一步使用 $form->populate($values) 。您必须通过其他步骤设置目标值:

  1. 从会话中获取数据
  2. 使用获取的数据设置表单元素值

Zend_Form generates an HTML form element with the form elements you specify. So its element capabilities are narrowed to a simple HTML form.

The hidden form element is used to pass those data that the user is not supposed to enter by hand. But as you yourself said it, there is no guaranty it could not be tampered. so no security is provided by using a hidden form value.

Most of times you'd better use server side values (like stored in sessions) to reference to values that are to be protected from user.

I suggest you keep the ID in a session value, and then you could use the session key in the hidden form field. this way the user can not change the target ID. However you are not able to use the $form->populate($values) on this in one step. you would have to set the target value with other steps:

  1. fetch data from the session
  2. set the form element value with the fetched data
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文