rustsec-2024-0446
Vulnerability from osv_rustsec
Published
2024-07-26 12:00
Modified
2025-12-22 13:54
Summary
Shell expansion in custom commands
Details

Summary

Undocumented and unpredictable shell expansion and/or quoting rules make it easily to accidentally cause shell injection when using custom commands with starship in bash.

Details

I wanted to show the git commit name in my prompt (I use bash), so I added a command:

[custom.git_commit_name]
command = 'git show -s --format="%<(25,mtrunc)%s"'
style = "italic"
when = true

To my surprise, when I had a commit with backticks in it, the backticks were expanded. e.g.:

touch foo
git add foo
git commit -m '`ls`'

Thankfully I noticed it on my own commit before checking out someone's code whose commit message was

rm -rf /important/stuff

The documentation says:

Command output is printed unescaped to the prompt

    Whatever output the command generates is printed unmodified in the prompt.
    This means if the output contains special sequences that are interpreted
    by your shell they will be expanded when displayed. These special
    sequences are shell specific, e.g. you can write a command module that
    writes bash sequences, e.g. \h, but this module will not work in a fish
    or zsh shell.

    Format strings can also contain shell specific prompt sequences, e.g. Bash, Zsh.

However, it doesn't specifically mention shell injection with $() and backticks; it just mentions the prompt escape sequences, and the link doesn't suggest any shell injection possibilities either.

Furthermore, I can't even figure out how to properly escape things, because simply changing the command to

command = 'printf %q "$(git show -s --format="%<(25,mtrunc)%s")"'

doesn't work, as it's also adding a backslash before spaces. I also tried use_stdin=false

I'm not 100% sure this qualifies as a vulnerability, but I feel it is not documented well enough to warn unsuspecting users, and it certainly is not documented how to properly quote things, because after 15-30 minutes of trying, I can't figure it out.

I see some past commits about fixing shell injection with $, and it does seem like the problem doesn't exist in build-in modules like git branch.

PoC

Have some custom command which prints out information from a potentially untrusted/unverified source.

[custom.git_commit_name]
command = 'git show -s --format="%<(25,mtrunc)%s"'
style = "italic"
when = true

Impact

People with custom commands, so the scope is limited, and without knowledge of people's commands, it could be hard to target people. The only one I saw in the example custom commands that may be vulnerable is the playerctl one.


{
  "affected": [
    {
      "database_specific": {
        "categories": [
          "code-execution"
        ],
        "cvss": "CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
        "informational": null
      },
      "ecosystem_specific": {
        "affected_functions": null,
        "affects": {
          "arch": [],
          "functions": [],
          "os": []
        }
      },
      "package": {
        "ecosystem": "crates.io",
        "name": "starship",
        "purl": "pkg:cargo/starship"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "1.0.1-0"
            },
            {
              "fixed": "1.20.0"
            }
          ],
          "type": "SEMVER"
        }
      ],
      "versions": []
    }
  ],
  "aliases": [
    "CVE-2024-41815",
    "GHSA-vx24-x4mv-vwr5"
  ],
  "database_specific": {
    "license": "CC-BY-4.0"
  },
  "details": "## Summary\n\nUndocumented and unpredictable shell expansion and/or quoting\nrules make it easily to accidentally cause shell injection\nwhen using custom commands with starship in bash.\n\n## Details\n\nI wanted to show the git commit name in my prompt (I use bash), so I added a command:\n\n```\n[custom.git_commit_name]\ncommand = \u0027git show -s --format=\"%\u003c(25,mtrunc)%s\"\u0027\nstyle = \"italic\"\nwhen = true\n```\n\nTo my surprise, when I had a commit with backticks in it,\nthe backticks were expanded. e.g.:\n\n```\ntouch foo\ngit add foo\ngit commit -m \u0027`ls`\u0027\n```\n\nThankfully I noticed it on my own commit before checking out\nsomeone\u0027s code whose commit message was\n\n`rm -rf /important/stuff`\n\nThe documentation says:\n\nCommand output is printed unescaped to the prompt\n\n```\n    Whatever output the command generates is printed unmodified in the prompt.\n    This means if the output contains special sequences that are interpreted\n    by your shell they will be expanded when displayed. These special\n    sequences are shell specific, e.g. you can write a command module that\n    writes bash sequences, e.g. \\h, but this module will not work in a fish\n    or zsh shell.\n\n    Format strings can also contain shell specific prompt sequences, e.g. Bash, Zsh.\n```\n\nHowever, it doesn\u0027t specifically mention shell injection with $()\nand backticks; it just mentions the prompt escape sequences, and\nthe link doesn\u0027t suggest any shell injection possibilities either.\n\nFurthermore, I can\u0027t even figure out how to properly escape things,\nbecause simply changing the command to\n\n```\ncommand = \u0027printf %q \"$(git show -s --format=\"%\u003c(25,mtrunc)%s\")\"\u0027\n```\n\ndoesn\u0027t work, as it\u0027s also adding a backslash before spaces. I also\ntried `use_stdin=false`\n\nI\u0027m not 100% sure this qualifies as a vulnerability, but I feel it is not\ndocumented well enough to warn unsuspecting users, and it certainly is\nnot documented how to properly quote things, because after 15-30 minutes\nof trying, I can\u0027t figure it out.\n\nI see some past commits about fixing shell injection with $, and it does\nseem like the problem doesn\u0027t exist in build-in modules like git branch.\n\n## PoC\n\nHave some custom command which prints out information from a potentially untrusted/unverified source.\n\n```\n[custom.git_commit_name]\ncommand = \u0027git show -s --format=\"%\u003c(25,mtrunc)%s\"\u0027\nstyle = \"italic\"\nwhen = true\n```\n\n## Impact\n\nPeople with custom commands, so the scope is limited, and without knowledge\nof people\u0027s commands, it could be hard to target people. The only one I saw\nin the example custom commands that may be vulnerable is the playerctl one.",
  "id": "RUSTSEC-2024-0446",
  "modified": "2025-12-22T13:54:49Z",
  "published": "2024-07-26T12:00:00Z",
  "references": [
    {
      "type": "PACKAGE",
      "url": "https://crates.io/crates/starship"
    },
    {
      "type": "ADVISORY",
      "url": "https://rustsec.org/advisories/RUSTSEC-2024-0446.html"
    },
    {
      "type": "ADVISORY",
      "url": "https://github.com/starship/starship/security/advisories/GHSA-vx24-x4mv-vwr5"
    }
  ],
  "related": [],
  "severity": [
    {
      "score": "CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Shell expansion in custom commands"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…