Fedora Account System
Red Hat Associate
Red Hat Customer
Disclaimer: Community trackers are created by Red Hat Product Security team on a best effort basis. Package maintainers are required to ascertain if the flaw indeed affects their package, before starting the update process. ### Summary When extra data is allowed, providing a `__pydantic_initialised__` key when validating a Pydantic V1 dataclass makes it considered as already validated, resulting in field values not being validated. ### Details When extra data is allowed, the `__init__()` method of Pydantic V1 dataclasses stores all the provided keyword arguments in the instance `__dict__` before validation ([`pydantic/dataclasses.py`](https://github.com/pydantic/pydantic/blob/v1.10.26/pydantic/dataclasses.py#L295-L298)): ```python elif config.extra == Extra.allow: for k, v in kwargs.items(): self.__dict__.setdefault(k, v) init(self, *args, **{k: v for k, v in kwargs.items() if k in self.__dataclass_fields__}) ``` A `__pydantic_initialised__` keyword argument thus overrides the internal flag used to skip validation of already validated instances ([`pydantic/dataclasses.py`](https://github.com/pydantic/pydantic/blob/v1.10.26/pydantic/dataclasses.py#L430-L434)): ```python def _dataclass_validate_values(self: 'Dataclass') -> None: # validation errors can occur if this function is called twice on an already initialised dataclass. # for example if Extra.forbid is enabled, it would consider __pydantic_initialised__ an invalid extra property if getattr(self, '__pydantic_initialised__'): return ``` The issue was fixed in commit https://github.com/pydantic/pydantic/commit/b26913fe6, published in V1.10.27. If you are relying on the `pydantic.v1` namespace in Pydantic V2, upgrade to [V2.14.2](https://github.com/pydantic/pydantic/releases/tag/v2.14.2) or later. ### Impact Validation bypass: data returned by validation doesn't match the declared type. Affected are applications validating untrusted data into Pydantic V1 dataclasses allowing extra data (with `extra=Extra.allow`).
Rawhide already has Pydantic ≥ 2.14.2, and all other branches can’t and won’t be updated due to various breaking changes. So the only question is whether this can be backported. Commit 6ec75e57f277a820ec583e601167f25fe8dc7c87 was the fix for Pydantic V1, which we don’t ship in Fedora. The “forward-port” to the pydantic.v1 namespace was https://github.com/pydantic/pydantic/commit/dd139b5ddc2fbbb63cb1a178104d35f5076ef550. I already cherry-picked this to F45 for bug 2578018, which will have fixed this issue as well. I’m not attempting the cherry-pick for F44, https://bugzilla.redhat.com/show_bug.cgi?id=2578018#c2, and I’m not working on F43 any more since it is so close to its end-of-life date.
*** Bug 2578219 has been marked as a duplicate of this bug. ***