diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 00000000..a629cb2c --- /dev/null +++ b/.jules/sentinel.md @@ -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. diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 1664e115..797ab55f 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -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 } ); }