dinhanhx / dinhanhx/fastapi-docx

🔒 Security: Wildcard CORS policy allows any origin

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Description

In `main.py` lines 21-25, CORS is configured with:
```python
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
```

This allows **any website** to make requests to the API, which could be exploited for:
- Unauthorized file conversion abuse (resource exhaustion)
- CSRF-like attacks if authentication is ever added

## Why It Matters

Even for an internal tool, wildcard CORS is a bad default. If deployed publicly, anyone can use your server as a free document conversion service.

## Suggested Fix

Restrict to known origins via environment variable:
```python
import os
origins = os.getenv("CORS_ORIGINS", "http://localhost:3000").split(",")
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=["POST", "GET"],
allow_headers=["*"],
)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.