Skip to content

🐛 fix(xsd): validate every base type's content - #2135

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/aqico59p
Nov 15, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/aqico59p

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Validation of a type derived by extension in two or more steps checked only the particle of its nearest base. Elements that the grandparent type requires were not enforced, so a document missing them was accepted, and a complete document could be rejected. ✅ After this change every particle along the base chain applies, so a document must satisfy all of them.

Architecture

XML Schema Part 1 defines the content of an extension as the base's content followed by the extension's own particle, applied recursively. The effective content of a type now collects every inherited particle, root-most type first. Children are matched against that list in order, each particle starting where the previous one stopped, and element declarations from every particle are collected for type checks. Children that an inherited type declares are type-checked as well.

An extension that adds an xs:all content model to a base with content is now rejected when the schema compiles. XML Schema Part 1 limits an xs:all group to the only particle of a content model, and the old matcher dropped the base's particles in that case.

Behavior changes

  • A type derived by extension in two or more steps requires the particles of every base type in its chain. Documents that omit an element required by an ancestor type are rejected, and complete documents that were rejected before are accepted.
  • An extension that adds an xs:all content model to a base with content raises ValueError when the schema is compiled.
  • An xs:all content model extended without particles, and a type that extends a base with no content, behave as before.

Fixes #1716.

A complex type derived by extension in two or more steps was matched only
against the particle of its nearest base. The particles of the types further
up the chain were dropped, so a document that omitted the elements those
types require was accepted, and a complete document was rejected.

The content is now the particles of the whole base chain, root-most type
first, followed by the type's own particle. Child elements are typed by the
declarations from every one of them.

An xs:all that extends a base with content is now a schema error, as XSD 1.0
requires. Before, the base's particles were dropped in that case as well.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:sec-fix/aqico59p (0f21224) with main (3e0b864)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

The check that rejects an xs:all added to a base with content asks whether a
group ref names an xs:all group. No test extended a base with content by a
group ref to a sequence group, so the branch that accepts such a group was
never run. The new test covers it, with a document that satisfies the base
and the group and one that omits an element of the group.
@gaborbernat
gaborbernat merged commit a301ead into tox-dev:main Nov 15, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLSchema ignores elements inherited through two or more extension steps

1 participant