Package groovy.xml

Class FactorySupport

java.lang.Object
groovy.xml.FactorySupport

public class FactorySupport extends Object
Support class for creating hardened JAXP factories.

Every create* method returns a factory pre-configured to resist common XML attack vectors (XXE, billion laughs, external resource resolution). Overloads accepting flags let callers relax specific defaults when they legitimately need DOCTYPE support or external resource resolution.

  • Field Details

    • DEFAULT_MAX_ELEMENT_DEPTH

      public static final int DEFAULT_MAX_ELEMENT_DEPTH
      Default bound on how deeply elements may nest in a parsed document.

      XMLConstants.FEATURE_SECURE_PROCESSING does not bound element depth: the JAXP jdk.xml.maxElementDepth limit defaults to 0, meaning unlimited. The parse itself survives an arbitrarily deep document, because SAX tracks nesting on the heap, but the first consumer to walk the result recursively — Node.text(), XmlNodePrinter, GPathResult.toString(), XmlUtil.serialize — runs one stack frame per level and dies with a StackOverflowError. That is an Error, so it escapes the catch (Exception) an application would reasonably use to handle a malformed document. Bounding the depth at parse time turns it into an ordinary parse failure, at one check point, before any of those consumers is reached.

      The value matches groovy.json's nesting bound, and sits far above any realistic document.

      Since:
      6.0.0
      See Also:
  • Constructor Details

    • FactorySupport

      public FactorySupport()
  • Method Details