Unconstrained type instantiation via YAML tag resolution in asset deserializer

Aperta
#3,632 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
security

Direzione di ricerca

Start in sources/core/Stride.Core.Yaml/Serialization/YamlAssemblyRegistry.cs at TypeFromTag() and ResolveSingleType(), then follow the path through TagTypeSerializer.cs, ObjectSerializer.cs and DefaultObjectFactory.cs. This is a security-sensitive report with reproduction withheld and no fix linked, so coordinate with maintainers before writing any change. Done means an unmarked type fails resolution while a [DataContract]-marked type still deserializes, and the existing YAML tests still pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area-Asset area-Serialization bug

Affected versions: confirmed on commit 036dfcc2a86bed3767fde88ea0bdc243ff81b709 (current default branch, master).

Summary

Stride's custom YAML deserializer (Stride.Core.Yaml) resolves an unrecognized YAML tag directly to a .NET type via reflection against every loaded assembly, including the standard library, with no check on what the resolved type actually is. The resolved type is then instantiated via the object factory and has its properties populated directly from the YAML mapping. This is reached whenever any Stride asset YAML file (.sdscene, .sdprefab, etc) is parsed, which happens from the ordinary workflow of opening a project or package, not only from running your own compiled code.

Details

sources/core/Stride.Core.Yaml/Serialization/YamlAssemblyRegistry.cs, TypeFromTag() (around lines 185-234): when a YAML node's tag isn't already a known registered alias, it resolves the tag string via ResolveType().

ResolveSingleType() (around lines 293-328): does assembly.GetType(typeName) against every assembly in lookupAssemblies, which always includes mscorlib/CoreLib (typeof(int).Assembly) plus every assembly registered via AssetYamlSerializer/YamlSerializer.RegisterAssembly. No base-type/interface constraint and no allowlist or denylist is applied to the result.

sources/core/Stride.Core.Yaml/Serialization/Serializers/TagTypeSerializer.cs, ReadYaml(): sets the deserialization context's type descriptor to the resolved type, only checking that a type was resolved at all, not what it is.

sources/core/Stride.Core.Yaml/Serialization/Serializers/ObjectSerializer.cs, CreateOrTransformObject() (around line 133-139): unconditionally instantiates the resolved type via ObjectFactory.Create().

sources/core/Stride.Core.Yaml/Serialization/DefaultObjectFactory.cs: the only gate before Activator.CreateInstance(type) is that the type has a public parameterless constructor, a shape check rather than a security check.

Live validation confirmed this end to end with a harmless test type (a plain class with one settable string property, no [DataContract] attribute): feeding !ProbeType\nMessage: hello-from-yaml through the real, unmodified Stride.Core.Yaml deserializer (via the same SerializerSettings.RegisterAssembly API Stride's own code uses) produced an instance of that type with its property populated from the YAML mapping. No allowlist, denylist, or [DataContract] gate exists anywhere in this chain prior to the fix in the attached PR.

Steps To Reproduce

(available upon request)

Impact

Opening a Stride project, package, or any individual asset file from an untrusted source (cloning a shared repository, downloading a sample project or template, collaborating on a shared package) parses its .sdscene/.sdprefab/asset YAML files through this deserializer. A YAML tag in such a file can cause the deserializer to instantiate any public, parameterless-constructible type currently loaded in the process, not just types intended for asset serialization, and to populate its properties directly from attacker-controlled YAML content. This was confirmed to work end to end against a harmless demonstration type; whether a specific loaded type's property setters can be chained into a more severe outcome (code execution, file write, etc) was not investigated as part of this report, consistent with responsible-disclosure scope, but the underlying primitive (arbitrary type instantiation plus property injection driven by untrusted input) is itself the reportable issue, matching the well-documented risk class of unconstrained polymorphic deserialization (CWE-502).

CVSS 3.1: AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:L (approximately 5.4, Medium)

CWE-502 (Deserialization of Untrusted Data)

A fix PR is attached: requires the resolved type (or a base type it inherits DataContractAttribute.Inherited from) to carry [DataContract] before TypeFromTag() returns it, mirroring the identical inheritance-walk already used elsewhere in the codebase (ObjectDescriptor's constructor) to resolve DefaultMemberMode from the same attribute. Verified in an isolated build: an unmarked type now fails resolution the same way an unknown tag already did, while a [DataContract]-marked type of the same shape still deserializes correctly.

Lingua principale
C#
Stelle
8k
Fork
1.2k
Merge medio
2g 7h
PR unite (30g)
316

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stride3d/stride

Tutte le issue di stride3d/stride

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.