Skip to content

🐛 fix(xsd): reject attributes on simple types - #2138

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/n44
Nov 15, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/n44

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

XMLSchema.validate() accepted an element with a simple type that carried attributes, and reported the document valid. XML Schema does not allow such an element to have attributes beyond the xsi: ones, so the document was wrong to pass. ✅ After this change the element fails with a structure error, and the document is reported invalid.

Under XML Schema Part 1, section 3.3.4, an element with a simple type may carry no attributes other than xsi:type, xsi:nil, xsi:schemaLocation and xsi:noNamespaceSchemaLocation. Namespace declarations are not attributes in the infoset, so they stay allowed.

The check runs in both simple-type routes: a built-in or named simple type, and an inline xs:simpleType. Local declarations and ref= to a global element reach the same check. The xsi: attributes are matched by namespace, so another prefix bound to the XSI namespace is accepted.

Behavior changes

  • An element with a simple type that carries an attribute other than a namespace declaration or one of the four xsi: attributes now produces one structure error for the element.
  • Prefixed attributes that complex types ignore, such as xml:* and attributes in other namespaces, are rejected on simple-typed elements, since the spec names no exception for them.

Fixes #2128.

XSD 1.0 §3.3.4 lets a simple-typed element carry no attributes except
the four xsi ones, but the simple-type branches never checked
attributes; only complex types did. Both simple-type branches now
check them: a type= reference and an inline simpleType.

Namespace declarations are not attributes in the infoset and stay
allowed. The xsi attributes are matched by namespace, so a different
prefix bound to the XSI namespace is accepted and an unrelated prefix
is not.

Fixes tox-dev#2128.
@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 degrade performance by 24.96%

2 warnings

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

❌ 1 regressed benchmark
✅ 581 untouched benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_mutating_feature[path-xpath-one-cold] 107.4 µs 143.2 µs -24.96%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:sec-fix/n44 (fe335c8) with main (f7c67d8)

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. ↩

@gaborbernat
gaborbernat merged commit af2a116 into tox-dev:main Nov 15, 2026
30 of 31 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 accepts attributes on simple-typed elements

1 participant