GHSA-h26w-r4m5-8rrf: CodeChecker has a Path traversal in `CodeChecker server` in the endpoint of `CodeChecker store`
SummaryZIP files uploaded to the server-side endpoint handling a `CodeChecker store` are not properly sanitized. An attacker can exercise a path traversal to make the `CodeChecker server` load and display files from an arbitrary location on the server machine.DetailsTargetThe vulnerable endpoint is `/<PRODUCT_URL>/v6.53/CodeCheckerService@massStoreRun`.Exploit overviewThe attack is made possible by improper sanitization at one point in the process.When the ZIP file is uploaded by `CodeChecker store`, it is first unzipped to a temporary directory (safely).When deciding which files to insert into CodeChecker's internal database, the decision is made based on the `content_hashes.json` in the ZIP. An attacker has control over the contents of this file.After reading that file, the paths specified in the JSON are normalized by this code:
https://github.com/Ericsson/codechecker/blob/fa41e4e5d9566b5a4f5a80a27bddec73a5146f5a/web/server/codechecker_server/api/mass_store_run.py#L442-L444Providing sufficiently many `../../`s inside the `content_hashes.json`, an attacker can control the insertion of completely arbitrary files into CodeChecker's internal database.This is confirmed in the log output:Once the file is inserted into the internal database, it can be displayed trivially on the Web interface.
As CodeChecker doesn't distinguish between filenames after the ZIP is extraced, an attacker can define aliases in `content_hashes.json`.The file is displayed in the Web UI if and only if there is at least one _bug report_ in it.
The bug reports are coming from the ZIP and the attacker can craft the required contents for this.
If done so, the logs confirm the requirement for presenting the results of the exploit will be triggered:The server emits the contents of the injected files from the server's database to all users:
![CodeChecker's Web UI showing the snapshot of the /etc/passwd file that was injected to the database due to the path traversal attack.](https://user-images.githubusercontent.com/16914176/278057281-2c6994ed-4c24-4026-a6b6-148ac43243ca.png)[!NOTE]  
The file is shown with the contents as it was on the system when the exploited `CodeChecker store` was exercised. This attack does not allow the server to return the "live" contents of a file on the server's storage &mdash; the attacker(s) must recurringly exercise the exploit to keep the injected files "updated" in the database.PoCThe minimal example that can trigger the exploit can be downloaded: [`PoC.zip`](https://github.com/Ericsson/codechecker/files/14757143/PoC.zip).The key to the exploit is the `content_hashes.json` file. The additional files create a report in the loaded `/etc/passwd` file, so it is displayed in the web UI.Uploading the ZIP to the serverThe communication between the `CodeChecker store` and the server is done by transmitting the ZIP file in a Base64-encoded string.  
Encoding the ZIP into the format of the API can be done with Python:The result of the compression and encoding can be sent to the running server over the API.
When the API is called, the exploit is exercised.ImpactThe path traversal vulnerability allows reading data on the machine of the `CodeChecker server`, with the same permission level as the `CodeChecker server` process. This allows for the exfiltration from the server-side storage medium.
If the `CodeChecker server` is run with authentication enabled (not the default configuration), then the attack requires a valid user account on the `CodeChecker server`, with the permission to store to a database, and view the stored reports.CVSS 3.1 Base Score: 6.5
[AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N](https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?vector=AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N&version=3.1)Reproducible up to version `6.22.1`.
CVSS v3.1: 6.5