Skip to content

LiteDB may deserialize bad JSON on object type using _type

Critical severity GitHub Reviewed Published Feb 24, 2023 in mbdavid/LiteDB • Updated Mar 6, 2023

Package

nuget LiteDB (NuGet)

Affected versions

< 5.0.13

Patched versions

5.0.13

Description

Impact

LiteDB use a special field in JSON documents to cast diferent types from BsonDocument do POCO classes. When instance of an object are not the same of class, BsonMapper use a special field _type string info with full class name with assembly to be loaded and fit in your model.
If your end-user can send to your app a plain JSON string, deserialization can load an unsafe object to fit in your model.

Patches

Version >= 5.0.13 add some basic fixes to avoid this, but is not 100% guaranteed when using Object type
Next major version will contains a allow-list to select what king of Assembly can be loaded

Workarounds

  • Avoid users send to your app a JSON string to be direct insert/update into database
  • Avoid use classes with Object type - try use an interface when possible

If your app send a plain JSON string to be insert/update into database, prefer this:

// Bad
public class Customer {
    public int Id { get; set; }
    public string Name { get; set; }
    public Object AnyData { get; set; } // <= Avoid use `Object` base type
}

// Good
public class Customer {
    public int Id { get; set; }
    public string Name { get; set; }
    public IDictionary<string, string> AnyData { get; set; } // Will accept only key/value strings
}

References

See this workaround fix on this commit:

mbdavid/LiteDB@4382ff4

References

@mbdavid mbdavid published to mbdavid/LiteDB Feb 24, 2023
Published to the GitHub Advisory Database Feb 24, 2023
Reviewed Feb 24, 2023
Published by the National Vulnerability Database Feb 24, 2023
Last updated Mar 6, 2023

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

EPSS score

0.296%
(70th percentile)

Weaknesses

CVE ID

CVE-2022-23535

GHSA ID

GHSA-3x49-g6rc-c284

Source code

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.