Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

## 2024-05-30 - Cloudinary Error Data Leak in Upload Route
**Vulnerability:** The `/api/upload` endpoint leaked detailed internal Cloudinary API errors (e.g. `cloudinaryError` object, `http_code`) in the JSON response when an image upload failed.
**Learning:** Detailed error logging was mixed with client response construction, causing internal service data (and potential configuration hints) to be exposed to external clients in the case of failure.
**Prevention:** Always separate internal logging from client-facing error messages. Catch blocks handling external APIs (like Cloudinary) should log full details via `console.error` on the server but return only generic, safe messages (e.g., "Failed to upload image") to the client.
9 changes: 5 additions & 4 deletions src/app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ export async function POST(request: NextRequest) {
} catch (error: any) {
console.error('Upload error:', error);

// Return detailed error message
// Security: Do not expose detailed Cloudinary error responses to the client.
// Instead, log the full error server-side and return a generic safe message.
const errorMessage = error?.message || error?.error?.message || 'Failed to upload image';
const errorDetails = {
const fullErrorDetails = {
error: errorMessage,
details: error?.http_code ? `HTTP ${error.http_code}` : undefined,
cloudinaryError: error?.error || undefined
};

console.error('Full error details:', errorDetails);
console.error('Full error details:', fullErrorDetails);

return NextResponse.json(
errorDetails,
{ error: 'Failed to upload image' },
{ status: 500 }
);
}
Expand Down