Vulnerabilities in pkg:nuget/LiteDB

PACKAGE
Advisory Identifier: GHSA-3x49-g6rc-c284
Advisory Summary

CVE-2022-23535 is a CRITICAL (CVSS 9.8) litedb may deserialize bad json vulnerability (CWE-502: Deserialization of Untrusted Data) affecting LiteDB libraries in the NuGet ecosystem. The issue involves litedb may deserialize bad json on object type using _type. Remediation is available by upgrading affected packages to version 5.0.13.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:nuget/LiteDB

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:nuget/LiteDB. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-3x49-g6rc-c284 CVE-2022-23535 CRITICAL LiteDB may deserialize bad JSON on object type using _type

CVE-2022-23535 at a Glance

CVE Identifier CVE-2022-23535
GHSA Identifier GHSA-3x49-g6rc-c284
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product LiteDB
Package Ecosystem NuGet
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2022-23535

To remediate this vulnerability, upgrade all affected LiteDB dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

LiteDB fixed: 5.0.13
Upgrade LiteDB to 5.0.13
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for LiteDB

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-23535, inspect your project dependencies for LiteDB:

inspect dependencies for LiteDB

Analyze the terminal output to locate any version of LiteDB in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.0.13), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In LiteDB, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: https://github.com/mbdavid/LiteDB/commit/4382ff4dd0dd8b8b16a4e37dfd29727c5f70f93f

CVE-2022-23535 Affected LiteDB Versions

1 component(s)
Fixed Versions:
5.0.13
Product / Package Ecosystem Affected Versions Fixed Version
LiteDB
NuGet
< 5.0.13
5.0.13

References

Frequently Asked Questions

What is CVE-2022-23535?
CVE-2022-23535 is a security vulnerability in LiteDB involving LiteDB may deserialize bad JSON on object type using _type under CWE-502: Deserialization of Untrusted Data.
Which LiteDB versions are affected?
Affected versions include releases prior to 5.0.13 across affected packages: LiteDB.
What version fixes CVE-2022-23535?
Upgrading to 5.0.13 (or the latest patched release for your respective branch) resolves the vulnerability.
Is LiteDB affected?
Yes, LiteDB is affected in releases prior to 5.0.13. Upgrade your dependency to 5.0.13 or later.
What is the CVSS score of CVE-2022-23535?
CVE-2022-23535 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-23535?
CVE-2022-23535 is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check NuGet dependencies for CVE-2022-23535?
Run the dependency tree command: 'inspect dependencies for LiteDB'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-3x49-g6rc-c284",
  "modified" : "2023-03-06T22:00:24Z",
  "published" : "2023-02-24T16:22:50Z",
  "aliases" : [ "CVE-2022-23535" ],
  "summary" : "LiteDB may deserialize bad JSON on object type using _type",
  "details" : "### Impact\nLiteDB 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.\nIf your end-user can send to your app a plain JSON string, deserialization can load an unsafe  object to fit in your model.\n\n### Patches\nVersion >= 5.0.13 add some basic fixes to avoid this, but is not 100% guaranteed when using `Object` type\nNext major version will contains a allow-list to select what king of Assembly can be loaded\n\n### Workarounds\n- Avoid users send to your app a JSON string to be direct insert/update into database\n- Avoid use classes with `Object` type - try use an interface when possible\n\nIf your app send a plain JSON string to be insert/update into database, prefer this:\n```\n// Bad\npublic class Customer {\n    public int Id { get; set; }\n    public string Name { get; set; }\n    public Object AnyData { get; set; } // <= Avoid use `Object` base type\n}\n\n// Good\npublic class Customer {\n    public int Id { get; set; }\n    public string Name { get; set; }\n    public IDictionary<string, string> AnyData { get; set; } // Will accept only key/value strings\n}\n\n```\n\n### References\nSee this workaround fix on this commit:\n\nhttps://github.com/mbdavid/LiteDB/commit/4382ff4dd0dd8b8b16a4e37dfd29727c5f70f93f\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "NuGet",
      "name" : "LiteDB"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.0.13"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mbdavid/LiteDB/security/advisories/GHSA-3x49-g6rc-c284"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-23535"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mbdavid/LiteDB/commit/4382ff4dd0dd8b8b16a4e37dfd29727c5f70f93f"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mbdavid/LiteDB/commit/d72c6774e6a13de2cfcd7d477d3575efeb75c8f2"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mbdavid/LiteDB"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mbdavid/LiteDB/releases/tag/v5.0.13"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-02-24T16:22:50Z",
    "nvd_published_at" : "2023-02-24T23:15:00Z"
  }
}