简体   繁体   English

使用JQuery进行内联页面编辑(就地编辑)时如何维护安全性

[英]How to maintain security when using JQuery for inline page editing (edit-in-place)

I want to allow users to edit items on their profile page after they have logged in (like on facebook). 我想允许用户登录后(如在Facebook上)在个人资料页面上编辑项目。 Lets call this page profile.cfm . 让我们将此页面称为profile.cfm

I am confused how to allow inline editing of a page (that is, replacing page elements with form inputs so the user can edit the content in place) only if the user is logged in and their credentials match those of the page they want to edit. 我很困惑如何仅当用户登录并且其凭据与他们要编辑的页面的凭据相匹配时才如何允许页面的内联编辑(即用表单输入替换页面元素,以便用户可以在适当位置编辑内容) 。

Traditionally, I would have a separate page for editing a profile like profile-edit.cfm . 传统上,我会有一个单独的页面来编辑profile-edit.cfm类的profile-edit.cfm On this page I would check that the ID of the profile they want to edit is the same as the ID stored in their Session variable. 在此页面上,我将检查他们要编辑的配置文件的ID是否与存储在其Session变量中的ID相同。 If everything matches up then the page will display. 如果一切都匹配,那么将显示该页面。 If not it will fail. 如果没有,它将失败。

However with JS inline editing, there is no separate edit page to take care of security checks. 但是,使用JS内联编辑时,没有单独的编辑页面可以进行安全检查。 So how can I enable the JS editing capability only when the correct user is logged-in? 那么,仅当正确的用户登录后,才能启用JS编辑功能吗? I don't want users modifying other people's profile of course. 我当然不希望用户修改其他人的个人资料。 Simply disabling/enabling the inline editing Javascript code based on log-in credentials isn't enough because that can easily be turned back on using Firebug etc. 仅基于登录凭据禁用/启用内联编辑Javascript代码是不够的,因为可以使用Firebug等轻松地将其重新启用。

Of course even though they can enable the javascript doesn't mean the server will accept the edit because it does its own validation. 当然,即使它们可以启用javascript也并不意味着服务器会接受编辑,因为它会执行自己的验证。 Its just that I'd rather users didn't have the option to even visually edit the page if they don't have the correct login credentials. 只是我希望用户如果没有正确的登录凭据,甚至没有选择甚至可以直观地编辑页面。

Is this just the expected trade-off for having javascript based controls that they may be visible to a user (who is of course maliciously amending the page) will not work correctly depending on other variables? 难道这只是预期的折中,因为基于javascript的控件可能对用户可见(他们当然是在恶意修改页面),但取决于其他变量,它们可能无法正常工作?

I'm stuck on this from a logic/conceptual point. 从逻辑/概念角度讲,我坚持这样做。

If I were you. 如果我是你。 I use ASP.NET C# for developing the web applications. 我使用ASP.NET C#开发Web应用程序。 And if I ever wish to have everything done on the client side using JQuery, Javascript I would do the following: 如果我希望使用JQuery在Java客户端上完成所有工作,则可以执行以下操作:

  • Decide which things identifies my client login and I have those available with me at the client side also. 确定哪些内容可以标识我的客户登录名,并且在客户端也可以与我一起使用。 Such as his ID, Session ID, Cookie, etc. 例如他的ID,会话ID,Cookie等。
  • Create an encryption technique. 创建一种加密技术。
  • Write that to a hidden field. 将其写入隐藏字段。
  • Compute the same at the client side and then match the result. 在客户端进行相同的计算,然后匹配结果。
  • If that is equal to the hidden field's value you have a authentic user. 如果该值等于隐藏字段的值,则您具有真实用户。 Else not. 否则没有。 And this can be done over and over again after small intervals. 并且可以在很小的间隔后反复进行此操作。

Example: Consider you have with you like profile id, username and session id. 示例:考虑您拥有个人资料ID,用户名和会话ID。 So you may create a pattern like say Username+Profile ID+Session ID and create a hash of that string. 因此,您可以创建一个模式,例如说用户名+配置文件ID +会话ID,并创建该字符串的哈希。 And then create the same at client side. 然后在客户端创建相同的内容。 And validate it then. 然后验证一下。 Hope that helps. 希望能有所帮助。

For Inline edit there has to be some initialization or some script which makes the form fields editable. 对于内联编辑,必须进行一些初始化或一些脚本,以使表单字段可编辑。 So include these script based on condition. 因此请根据情况包括这些脚本。 Form Example 表格范例

If(session[ID] == Profile ID){
   <script type="text">
       Add all your scripts which will allow inline editing.
   </script>
}

If the condition does not meet then the scripts will not be included and hence the form fields will not be editable. 如果不满足条件,则将不包含脚本,因此表单字段将不可编辑。 Hope this helps. 希望这可以帮助。

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

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