AntiXSS,由微软推出的用于防止XSS攻击的一个类库,可实现输入白名单机制和输出转义
  文章最后有antixx演示工程下载
  antixss下载地址
  http://www.microsoft.com/download/en/details.aspx?id=5242
  msi安装程序,安装之后,安装目录下有以下文件
  AntiXSS.chm   包括类库的操作手册参数说明
  HtmlSanitizationLibrary.dll    包含Sanitizer类(输入白名单)
  AntiXSSLibrary.dll    包含Antixss,Encoder类(输出转义)
  使用时在工程内添加引用HtmlSanitizationLibrary.dll 和AntiXSSLibrary.dll
  导入命名空间using Microsoft.Security.Application;
  1、输入白名单
  调用Sanitizer.GetSafeHtmlFragment方法即可,url_c未过滤后的干净字串
  url = Request.QueryString["url"];
  url_c = Sanitizer.GetSafeHtmlFragment(url);
  Response.Write(url_c);
  2、输出转义
  //HTML内容编码
  html_cont = Encoder.HtmlEncode(url);
  //html_cont = url;
  //HTML属性编码
  input1.Value = Encoder.HtmlAttributeEncode(url);
  //input1.Value = url;
  //对js进行编码
  url_c = Encoder.JavaScriptEncode(url);
  //url_c = url;
  //URL编码
  img1.Src = Encoder.UrlEncode(url);
  //img1.Src = url;
  XmlDocument xmlDoc;
  XmlNodeList nodeList;
  //XML属性编码
  isbn = Encoder.XmlAttributeEncode(Request.QueryString["isbn"]);
  if (isbn != null)
  {
  xmlDoc = new XmlDocument();
  xmlDoc.Load(Server.MapPath("db.xml"));
  nodeList = xmlDoc.SelectSingleNode("Employees").ChildNodes;
  foreach (XmlNode xn in nodeList)
  {
  XmlElement xe = (XmlElement)xn;
  if (xe.GetAttribute("genre") == "张三")
  {
  xe.SetAttribute("ISBN", isbn);
  }
  }
  xmlDoc.Save(Server.MapPath("db.xml"));
  }
  //XML内容编码
  price = Encoder.XmlEncode(Request.QueryString["price"]);
  price = Request.QueryString["price"];
  if (price != null)
  {
  xmlDoc = new XmlDocument();
  xmlDoc.Load(Server.MapPath("db.xml"));
  nodeList = xmlDoc.SelectSingleNode("Employees").ChildNodes;
  foreach (XmlNode xn in nodeList)
  {
  XmlElement xe = (XmlElement)xn;
  if (xe.GetAttribute("genre") == "张三")
  {
  XmlNodeList nls = xe.ChildNodes;
  foreach (XmlNode xn1 in nls)
  {
  XmlElement xe2 = (XmlElement)xn1;
  if (xe2.Name == "price")
  {
  xe2.InnerText = price;
  }
  }
  }
  }
  xmlDoc.Save(Server.MapPath("db.xml"));
  }
  以下为表示层
  <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  <form action="" >price=90</a></td>
  <td><%=price %></td>
  </tr>
  </table>
  </form>
  </asp:Content>

相关文章:

  • 2021-12-22
  • 2021-09-23
  • 2021-11-08
  • 2021-08-13
  • 2021-08-12
  • 2021-08-17
  • 2021-08-17
猜你喜欢
  • 2021-11-16
  • 2021-10-06
  • 2021-10-05
  • 2022-02-09
  • 2021-06-05
  • 2021-07-20
  • 2021-06-29
相关资源
相似解决方案