简体   繁体   English

如何保护我的html元素值?

[英]How do i secure my html element value?

I am developing an eCommerce website where user can select main product and also some extra accessories as per product.Also calculating total price (main product + accessories) to show it to user. 我正在开发一个电子商务网站,用户可以在其中选择主要产品以及每个产品一些额外的附件,还可以计算总价(主要产品+附件)以显示给用户。

For now i am storing product price,individual accessories price and total price in hidden html input tag but it is easily accessible from inspect window. 现在,我将产品价格,单个配件价格和总价格存储在隐藏的html输入标签中,但可以从检查窗口轻松访问。

How do i make it more secure? 我如何使其更安全?

The value stored on the page or inside a cookie should be just for the users view, it shouldn't be used for backend validation since anything stored on the users machine could potentially be changed by the user. 存储在页面或cookie内的值应仅用于用户视图,不应将其用于后端验证,因为用户计算机上存储的任何内容都可能被用户更改。

As others have stated, you should be validating the price with your backend software at checkout. 正如其他人所说,您应该在结帐时使用后端软件验证价格。

Hi there is one rule nothing in client side is secure. 嗨,有一个规则在客户端没有什么是安全的。 So once you will display something to user than this is not secure. 因此,一旦向用户显示内容,那将是不安全的。 If you have something that has to be secure (some client ids certificate, tokens ... ) You have to handle this on backend. 如果您有某些必须安全的东西(某些客户端ID证书,令牌...),则必须在后端进行处理。

You can just hide this information, but on backend you have to always validate inputs. 您可以只隐藏此信息,但是在后端,您必须始终验证输入。 User can do fake request, change values etc. 用户可以提出虚假请求,更改值等。

而不是存储产品价格 ,您应该存储产品ID,然后在后端获取用户选择的特定ID的价格,进行总和或任何其他需要进行的计算并将其保存在数据库中。

For Securing Hidden you can also apply encryption and hashing to hidden input fields, 对于“保护隐藏”,您还可以将encryption and hashing应用于隐藏的输入字段,

  • Hash the original value 散列原始值
  • Encrypt the original value 加密原始值
  • Send the encrypted value along with the hash digest 发送加密的值以及哈希摘要
  • Upon receiving back the data, decrypt the encryption, hash the result and compare it to the received hash digest to ensure the value remained unchanged 收到数据后,解密加密,对结果进行哈希处理并将其与接收的哈希摘要进行比较,以确保该值保持不变

Reference From : Securing HTML hidden input fields 参考来自: 保护HTML隐藏的输入字段

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

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