请勿将 WebLogic servlet 属性用于 XML 解析

此规则会检测是否使用了 WebLogic setAttribute 和 getAttribute 属性来解析 XML。 此规则会检测 Java 代码。 另一规则会检测是否使用了 WebLogic weblogic.servlet.XMLParsingHelper(用来启用此功能部件)。

会检测到下列情况:
  1. setAttribute 的所有方法调用,其中第一个自变量为具有下列任何值的字符串字面值:
    • org.xml.sax.helpers.DefaultHandler
    • org.xml.sax.HandlerBase
    • org.w3c.dom.Document

    例如:
    request.setAttribute("org.xml.sax.helpers.DefaultHandler", someObject)

  2. setAttribute 的所有方法调用,其中第一个自变量为对字符串变量或字符串字段的引用,并且该变量或字段初始化为下列任何值:
    • org.xml.sax.helpers.DefaultHandler
    • org.xml.sax.HandlerBase
    • org.w3c.dom.Document

    例如:
      String handler = "org.xml.sax.helpers.DefaultHandler";
      request.setAttribute(handler, someObject);

  3. getAttribute 的所有方法调用,其中自变量为具有下列任何值的字符串字面值:
    • org.xml.sax.helpers.DefaultHandler
    • org.xml.sax.HandlerBase
    • org.w3c.dom.Document

    例如:Document myDocument = request.getAttribute("org.w3c.dom.Document")

  4. getAttribute 的所有方法调用,其中自变量为对字符串变量或字符串字段的引用,并且该变量或字段初始化为下列任何值:
    • org.xml.sax.helpers.DefaultHandler
    • org.xml.sax.HandlerBase
    • org.w3c.dom.Document

    例如:
      String handler = "org.w3c.dom.Document";
      Document myDoc = request.getAttribute(handler);


在源扫描程序中,为此规则提供了快速修订。 根据代码的构成方式,快速修订会提供下列任何选项:
  1. 删除方法调用。

    例如:
      request.setAttribute("org.xml.sax.helpers.DefaultHandler", myHandler);
      request.getAttribute("org.w3c.dom.Document");
    当快速修订应用于前面的行时,那些行会被删除。
    注意:如果后面在代码内使用了对象 myHandler,请验证是否已通过其他方式初始化该对象。

  2. 删除变量初始化方法部分。

    例如:
      Document myDocument = request.getAttribute("org.w3c.dom.Document");
    当应用了快速修订时,前面的代码会被更改为:
      Document myDocument;
    注意:如果后面在代码内使用了对象 myDocument,请验证是否已通过其他方式初始化该对象。