Unencrypted view state in ASP.NET 2.0 could leak sensitive information

https://www.rapid7.com/db/vulnerabilities/http-asp-dot-net-unencrypted-viewstate

https://msdn.microsoft.com/en-us/library/ms972427.aspx

Because it's not formatted as clear text, folks sometimes assume that ViewState is encrypted—it's not. Instead, ViewState is merely base64-encoded to ensure that values are not altered during a roundtrip, regardless of the response/request encoding used by the application.

There are two levels of ViewState security you may wish to add to your application:

  • Tamper-proofing
  • Encryption

It's important to note that ViewState security has a direct effect on the time required to process and render an ASP.NET page. In short, more secure is slower, so don't add security to ViewState if you don't need it.

Tamper-Proofing  防止篡改

A hashcode will not secure the actual data within the ViewState field, but it will greatly reduce the likelihood of someone tampering with ViewState to try to spoof your application, that is, posting back values that your application would normally prevent a user from inputting.

You can instruct ASP.NET to append a hashcode to the ViewState field by setting the EnableViewStateMAC attribute:

<%@Page EnableViewStateMAC=true %>

EnableViewStateMAC can be set at the page or application level. Upon postback, ASP.NET will generate a hashcode for the ViewState data and compare it to the hashcode store in the posted value. If they don't match, the ViewState data will be discarded and the controls will revert to their original settings.

By default, ASP.NET generates the ViewState hashcode using the SHA1 algorithm. Alternatively, you can select the MD5 algorithm by setting <machineKey> in the machine.config file as follows:

<machineKey validation="MD5" />

Encryption  加密

You can use encryption to protect the actual data values within the ViewState field. First, you must set EnableViewStatMAC="true", as above. Then, set the machineKey validation type to 3DES. This instructs ASP.NET to encrypt the ViewState value using the Triple DES(Triple Data Encryption Algorithm三重数据加密算法) symmetric encryption algorithm.

<machineKey validation="3DES" />

ViewState Security on a Web Farm

By default, ASP.NET creates a random validation key and stores it in each server's Local Security Authority (LSA).

In order to validate a ViewState field created on another server, the validationKey for both servers must be set to the same value.

If you secure ViewState by any of the means listed above for an application running in a Web Farm configuration, you will need to provide a single, shared validation key for all of the servers.

The validation key is a string of 20 to 64 random, cryptographically-strong bytes, represented as 40 to 128 hexadecimal characters. Longer is more secure, so a 128-character key is recommended for machines that support it. For example:

<machineKey validation="SHA1" validationKey="
F3690E7A3143C185AB1089616A8B4D81FD55DD7A69EEAA3B32A6AE813ECEECD28DEA66A
23BEE42193729BD48595EBAFE2C2E765BE77E006330BC3B1392D7C73F" />

Summary

ASP.NET ViewState is a new kind of state service that developers can use to track UI state on a per-user basis.

There's nothing magical about it.

It simply takes an old Web programming trick—roundtripping state in a hidden form field—and bakes it right into the page-processing framework.

But the result is pretty wonderful—a lot less code to write and maintain in your Web-based forms.

You won't always need it, but when you do, I think you'll find ViewState is a satisfying addition to the feast of new features ASP.NET offers to page developers.

扩展阅读

Taking a Bite Out of ASP.NET ViewState

Understanding ASP.NET View State

How To: Configure MachineKey in ASP.NET 2.0

最新文章

  1. css 通用reset,common
  2. centos 6.5重置Root密码
  3. SpringBoot的简单应用以及部署
  4. android显示当前时间
  5. Valgrind简单用法
  6. 使用viewpager实现广告条轮询的效果
  7. 无法在web服务器上启动调试,此项目在使用一个被配置为使用特定IP地址的网站。请在项目URL中指定计算机名称。
  8. 【原创】08. easyui form控件,回调参数存在后缀 audio controls=&quot;controls&quot; style=&quot;display: none;&quot;&gt;&lt;/audio&gt;
  9. ArcGIS API for JavaScript 4.2学习笔记[16] 弹窗自定义功能按钮及为要素自定义按钮(第五章完结)
  10. 01基于配置文件方式的SpringMVC,三种HandlerMapping,三种控制器
  11. Asp.Net WebAPI中Filter过滤器的使用以及执行顺序
  12. 区别 chown和chmod的用法
  13. jQuery判断鼠标滚动方向
  14. Exp5MSF基础应用——20164325王晓蕊
  15. Mayor&#39;s posters(线段树+离散化)
  16. csp20160904解题报告
  17. MySQL的btree索引和hash索引的区别 (转)
  18. java maven 操作 收集的一些命令
  19. Docker CE部署
  20. iOS从当前隐藏导航界面push到下一个显示导航界面出现闪一下的问题

热门文章

  1. 【POJ 3273】 Monthly Expense (二分)
  2. DB-MySQL:MySQL 索引
  3. linux执行shell脚本时提示bad interpreter:No such file or directory的解决办法
  4. matlab基本语法
  5. maven、spring jdbc与mysql、mybatis
  6. Android Fragment RecycleListView
  7. 解决Ubuntu不能全屏问题
  8. Oracle数据库基础(一)
  9. js 手机号码简单正则校验
  10. 读书笔记之《HTML5 与 CSS3 基础教程》