Mica::XML::ParserOptions
Options for one parse: namespace processing, the safety limits and the work budget.
Every parse is secure by default. External DTD subsets and external entities are never fetched (the library has no network or file access), the limits below stop entity-expansion and nesting attacks early, and the work budget stops any input that would make parsing do more than a constant amount of work per byte.
options = Mica::XML::ParserOptions.new(max_element_depth: 64)
document = Mica::XML.parse(xml, options)
Constants
The default work budget for parsing: 64 operations per byte read (or expanded from an entity or a DTD default), plus 1,000,000, and at most 60 seconds of wall-clock time. Legitimate documents use well under a quarter of this allowance (see the README).
Constructors
Instance methods
Accepts a document type declaration. When false, the reader raises
Mica::XML::DocumentTypeNotAllowedError as soon as it recognizes
<!DOCTYPE, before it reads the internal subset or expands any
parameter entity. Request bodies and other untrusted input that never
needs a DTD should turn it off.
Verifies XML 1.1 full normalization (section 2.13): every text,
attribute value, comment, PI, CDATA section and name is in Unicode
NFC, and none of them starts with a composing character. Raises
Mica::XML::NormalizationError. Applies to XML 1.1 documents.
Maximum total bytes of attribute values added from DTD defaults in one document.
Maximum length in bytes of a single name (element, attribute, entity, PI target, name token).
Maximum size in bytes of one token: a text node, attribute value, comment, PI, CDATA section or the internal DTD subset.
The work budget and deadline every parse runs under. The deadline is
checked at work-budget checkpoints, after every IO read that returns,
and at the start and end of the parse; it bounds the parser's own
work. A read from a blocking IO that never returns cannot be
interrupted, so for a guaranteed wall-clock bound over an untrusted
stream give the IO its own read timeout (for example
Socket#read_timeout).