Repository navigation
perf(bench): compare against competitors at CLI and library level - #314
Conversation
libxmlsec1 `encrypt --xml-data DATA --node-id ID TEMPLATE` fills the first EncryptedData of the template, resolves ID in DATA, encrypts that element (or its children for Content) and writes DATA with the EncryptedData in place. The CLI applied --node-id to the template, always encrypted the data root and wrote the rendered template, so an element inside a document could not be encrypted. - Resolve --node-id in the --xml-data document and replace the selected element or its children there; output the data document. - Take the template from its first EncryptedData. - Refuse templates whose EncryptedData refers to other template nodes by #id, since only the EncryptedData moves into the data document. - Accept --session-key aes-128|aes-192|aes-256 when it matches the template AES method and an EncryptedKey recipient carries the key. The process-contract tests that asserted template-subtree selection and content-only decryption output now assert libxmlsec1's behavior, checked against the pinned 1.3.13 CLI. A reciprocal oracle test encrypts an element in place with RSA-OAEP and AES-256-GCM in both directions. Closes #299
- Select the data node by --node-name as libxmlsec1 does: split at the
last colon into namespace URI and local name, take the first element
in document order with that expanded name, and fail with "failed to
find node with name" otherwise. --node-id still takes precedence.
- Refuse output that exceeds the XML document limit once the filled
EncryptedData replaces the selected node, instead of writing a
document the CLI cannot read back.
- Resolve XPointer references of the moved EncryptedData with the same
dereferencing the core uses, so a #xpointer(id('x')) reference to a
template node outside it is refused like a bare #x.
Regression tests: xml_data_node_name_selects_the_first_matching_element,
xml_data_output_obeys_the_document_limit and
xml_data_template_references_resolve_xpointer_forms. The node-name
selection matches the pinned libxmlsec1 1.3.13 CLI on the same inputs.
- Parse the assembled --xml-data document under the full operation policy before writing it. The data document and the filled template each fit their limits, but a leaf replaced at the depth limit nests the EncryptedData children beyond it, and decryption refused the written output. - Undeclare the default namespace on the moved EncryptedData when the template has none and its new parent provides one, so unprefixed template metadata keeps its expanded name (Namespaces in XML 1.0, section 6.2). - Check same-document references with the element resolution the core key-source parser uses instead of projecting the target subtree per URI, which was quadratic in templates with many references. A #xpointer(/) reference is refused: after the move it would select the data document. Regression tests: xml_data_output_obeys_the_structural_limits, xml_data_moved_template_keeps_its_absent_default_namespace and the #xpointer(/) case of xml_data_template_references_resolve_xpointer_forms.
- Resolve the moved EncryptedData's references in the assembled data document, where decryption resolves them, and require an unambiguous target inside the moved element. A template ID that the data document also uses passed the template-only check, and decryption then refused the ambiguous reference. - Keep a template's own `xmlns=""` instead of adding a second one, which made the opening tag carry a duplicate attribute (Namespaces in XML 1.0, section 6.3) and refused the template. Regression tests: xml_data_references_stay_unambiguous_in_the_data_document and xml_data_moved_template_keeps_its_own_default_undeclaration.
The self-containment check treated every `URI` attribute under the moved EncryptedData as a reference, so application metadata in EncryptionProperty (XMLEnc 1.1 section 3.7), which decryption never resolves, made a valid template look dangling. Only CipherReference, RetrievalMethod, KeyInfoReference, DataReference and KeyReference are checked now; other `URI` attributes are preserved as they are. Regression test: xml_data_ignores_uri_attributes_of_extension_metadata.
The CLI comparison measured only signed payloads and byte-oriented symmetric encryption. Add the workloads applications run: - SAML assertion sign and verify; verification trusts only a root CA and receives the signer certificate and an untrusted intermediate. - Element encryption to an RSA-OAEP recipient certificate, standalone and in place inside its document. - A reference transformed by an XSLT stylesheet. Every output is verified or decrypted by every engine before timing, and each engine must reject a changed signed value. Capabilities the pinned Bergshamra CLI lacks (XSLT, in-place element encryption) are recorded as unsupported with the reason and never timed. The report schema and the dashboard carry the new workloads. Part of #298
An identity provider writes its certificate into the signature, and a relying party must reject signature wrapping. The assertion workload now signs with key and certificate into an empty X509Data, verifies the result through the trusted root without rewriting KeyInfo, and requires every verifier to reject a forged assertion that repeats the signed ID ahead of the signed one. Unsupported work is recorded per operation: Bergshamra leaves X509Data empty and cannot encrypt in place, but it verifies the other engines' assertions and decrypts their in-place documents, so those operations are measured. Part of #298
Process launch and key loading dominate the CLI comparison for small documents, so it cannot show what one operation costs. Add a library level, reported in its own dashboard section and never ranked against the CLI level: - xml-sec through its Rust API, Bergshamra through its Rust API from benchmarks/competitors (a project outside the workspace with its own lockfile and the pinned revision), and libxmlsec1 through its C API; - parse-and-operation and prepared-document boundaries for the SAML assertion, element, in-place element and XSLT workloads; - every result each engine produces is consumed by every other engine before timing, and every verifier must reject the tampered and the wrapped input; a harness reports an operation its engine lacks with the reason, recorded as unsupported and never timed; - allocation counts come from separate instrumented builds: a counting global allocator for Rust and, on glibc, a malloc-family replacement for C. The tracked ignore file keeps only build artifacts of the project and the competitor lockfile it publishes. Part of #298
Both comparison levels measured only 16 and 256 repeated units (at most 27 KB), where libxmlsec1's fixed process cost dominates and per-byte cost is invisible. Every CLI payload shape, workload and library case now also runs at 16384 units: the SAML response is about 1.7 MB, the other shapes 0.25-1.7 MB. The in-repository Divan benches keep their sizes.
The xmloxide backend charged predefined references, character references and predefined references inside entity replacement text against the entity expansion ceiling, documented as the limit on general-entity substitutions. None of them substitutes a declared entity or amplifies input, so a well-formed document with more than 10000 escaped characters (for example ` ` in certificate base64 or `&` in URLs) was refused. Only references to declared entities are charged now, matching the lexical preflight and the roxmltree backend; the document byte ceiling and the replacement-work ceiling still bound the others. Regression tests: entity_ceiling_tests runs on every compiled backend. The parser's own limit tests now count declared entities instead of predefined and character references. Closes #311
- Harnesses report a resource-limit refusal under the engine's default policy as unsupported work with its reason (exit 3) instead of failing the whole comparison. - The comparison runners take the canonical result from the first engine that produced one and exclude refusing verifiers from rejection checks, so a 16384-unit workload one engine refuses is still validated across the others.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 24 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bac1866e84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Every consuming probe now writes its own result, and decryption output is compared with the plaintext on the prepared boundary as well as the parse boundary. A prepared decryptor that returned other content was timed and published as validated. Regression test: a fake harness that is wrong only on the prepared boundary stops the run. - The Rust allocation profile counts live bytes as the allocator's usable block sizes, as the glibc profile of the C harness does, so the peak heap metric includes allocator rounding for every engine. Regression test: a one-byte allocation charges its whole block.
The vendored parser is verified against upstream 0.5.0 plus the maintained delta; regenerate the delta so it carries the entity expansion ceiling change and the verification step passes.
…erf/#298-competitor-levels # Conflicts: # src/document.rs
The in-process libxmlsec1 harness parsed with XML_PARSE_NONET alone, so each document interned its names in its own dictionary. Element encryption moves the template node into the data document; with libxml2 2.9 the moved names stay in the template's dictionary and are later passed to free() with the data document. glibc aborts on that, which stopped the Linux comparison at the first encryption probe. The harness now parses with xmlSecParserGetDefaultOptions(), the options the xmlsec1 command line uses, including XML_PARSE_NODICT. The defect needs glibc with libxml2 2.9 to show; macOS, including its guard allocator, does not abort. The Linux comparison job is the regression check: it failed at this probe before the change.
Summary
Benchmarks xml-sec against libxmlsec1 1.3.13 and Bergshamra at two levels and three document sizes.
docs/benchmarks.mdcover the three sizes.benchmarks/competitorsproject with its own lockfile and a pinned revision; a test asserts the product dependency graph never contains it.Includes the entity expansion ceiling fix from #312 (the 16384-unit SAML documents exposed it); those commits drop out once #312 lands. Stacked on #300.
Findings at 16384 units
These are from code without #305 and #307.
Testing
cargo nextest run --workspace(5158 passed, with the xmlsec1 1.3.13 oracle)cargo clippy --workspace --all-targets -- -D warningscargo fmt --check,cargo clippy --all-targetswith and withoutallocation-profile,cargo nextest run --features allocation-profilenode --test scripts/compare-security.test.mjs scripts/compare-library.test.mjs(26 passed)Closes #298