AI Resource Pro / website / SECURITY_UPDATES.md
Blog API Security Updates
Overview
This document outlines the security improvements implemented and needed for the blog API endpoints. All write operations (POST, PUT, DELETE) must be secured with both admin authentication and API key validation.
Security Requirements
All write operations on blog endpoints must implement:
- Admin authentication via Supabase (
validateRequest()withisAdmincheck) - API key validation (
validateApiKey())
Ideally, use the validateAdminApiRequest() middleware which implements both checks.
Already Updated
- ✅
/src/app/api/blog/route.ts- Main blog API (POST, PUT, DELETE) - ✅
/src/app/api/admin/blog/create/route.ts- Admin blog creation
Remaining Routes to Update
The following routes need to be updated to use the validateAdminApiRequest() middleware:
/src/app/api/admin/blog/update/route.ts/src/app/api/admin/blog/delete/route.ts/src/app/api/admin/blog/upload-image/route.ts/src/app/api/admin/blog/route.ts/src/app/api/admin/blog/[id]/route.ts/src/app/api/admin/blog/categories/route.ts
Implementation Pattern
Replace the existing authentication check:
const { user } = await validateRequest();
if (!user || !user.isAdmin) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
With the secure middleware:
// Validate security requirements for admin API endpoints
const securityError = await validateAdminApiRequest(request);
if (securityError) {
return securityError;
}
Don't forget to import the middleware:
import { validateAdminApiRequest } from '@/middleware/protected-routes';
And ensure the request parameter is properly typed as NextRequest:
export async function POST(request: NextRequest) {
// ...
}
Testing
After implementing these changes, test all endpoints with:
- Valid admin authentication + valid API key (should succeed)
- Valid admin authentication + invalid API key (should fail)
- Invalid admin authentication + valid API key (should fail)
- Invalid admin authentication + invalid API key (should fail)