Skip to content
Path traversal Disclosed report Intermediate

Internal machine learning API endpoint for CWE classification is vulnerable to path traversal

The report_weakness_id inference endpoint built a model directory path directly from the version and trained_at request fields, so path traversal sequences could escape the intended models folder. An attacker who could also place a joblib file on the server could then have it loaded and executed as arbitrary Python code.

jobert Follow

Originally disclosed on HackerOne

Medium 6.4 View original
  • Triaged in under an hour
  • Fixed in 15 days
  • Disclosed after 15 days

HackerOne has an internal machine learning API that exposes inference endpoints for numerous machine learning / artificial intelligence solutions. In one of the endpoints, /predict/report_weakness_id, which is used to classify report input, a path traversal vulnerability exists that could lead to remote code execution.

Proof of concept

The request.version and request.trained_at parameters are both vulnerable to path traversal. To reproduce, run any of the following curl commands inside the local Docker container:

trained_at

curl -X POST http://localhost:8082/predict/report_weakness_id -H 'content-type: application/json' -d'{"version":"v1", "trained_at": "2023-01-01T00:00:00Z/../../..", "input": [{"title": "test xss", "num_of_top_predictions": 3}]}'

version

curl -X POST http://localhost:8082/predict/report_weakness_id -H 'content-type: application/json' -d'{"version":"v1/../../../..", "trained_at": "2023-01-01T00:00:00Z", "input": [{"title": "test xss", "num_of_top_predictions": 3}]}'

The vulnerable code is shown below. The version and trained_at inputs are interpolated directly into the path, as can be seen on line 29. The AutoTokenizer.from_pretrained function is then called to load the tokenizer into memory.

Python
@app.post(
    "/predict/report_weakness_id",
    summary="An endpoint to suggest report's weakness id.",
)
async def report_weakness_id(request: ReportWeaknessIdModelRequest):
    """
    To try the endpoint in the Swagger UI, click on **Try it out** and copy-paste the below example in the request body box
    ```
    {
        "version":"v1",
        "trained_at": "2023-01-01T00_00_00Z",
        "input": [
            {
                "title": "test xss",
                "num_of_top_predictions": 3
            }
        ]
    }
    ```
    """
    input = request.input[0]
    title = preprocess_text(input.title)

    top_n = int(
        input.num_of_top_predictions or 3
    )  # as a start, it's by default set as 3

    model_dirpath = pathlib.Path(
        f"{os.path.dirname(__file__)}/../models/report_weakness_id/{request.version}/{request.trained_at}/"
    )

    tokenizer = AutoTokenizer.from_pretrained(model_dirpath, use_fast=True)

Impact

An attacker would be able to execute arbitrary python code if they were able to get a joblib file onto the ML API (i.e. as a temporary file).

The original report as published on HackerOne, by jobert. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

User-controlled version and trained_at values were interpolated into a filesystem path without validation, allowing traversal outside the models directory.

Impact

An attacker could execute arbitrary Python code if they were also able to get a joblib file onto the ML API, for example as a temporary file.

What the attacker needed

Access to the ML API endpoint; ability to place a joblib file on the server

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The service builds a file path by gluing together user-supplied text, so someone can use '..' to climb out of the intended folder. If they can also drop a malicious model file somewhere on the machine, the service will load it and run its code. This is called path traversal, and it becomes serious when the loaded file can execute code.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by jobert

View all

67 more disclosed reports, best first.

More from HackerOne

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.