Compare commits

..

3 Commits

Author SHA1 Message Date
gpt-engineer-app[bot]
576899cf25 Add ban evasion reporting to edge function
Added ban evasion reporting to the `upload-image` edge function for both DELETE and POST operations. This ensures that all ban evasion attempts, including those via direct API calls, are logged to `system_alerts` and visible on the `/admin/error-monitoring` dashboard.
2025-11-08 00:58:00 +00:00
gpt-engineer-app[bot]
714a1707ce Fix photo upload ban evasion reporting
Implement ban evasion reporting for the photo upload component to ensure consistency with other submission types. This change adds a call to `reportBanEvasionAttempt` when a banned user attempts to upload photos, logging the incident to system alerts.
2025-11-08 00:47:55 +00:00
gpt-engineer-app[bot]
8b523d10a0 Connect to Lovable Cloud
The user approved the use of the Lovable tool. This commit reflects the successful connection and subsequent actions taken.
2025-11-08 00:40:41 +00:00
3 changed files with 75 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import { logger } from "@/lib/logger";
import { breadcrumb } from "@/lib/errorBreadcrumbs";
import { checkSubmissionRateLimit, recordSubmissionAttempt } from "@/lib/submissionRateLimiter";
import { sanitizeErrorMessage } from "@/lib/errorSanitizer";
import { reportBanEvasionAttempt } from "@/lib/pipelineAlerts";
/**
* Photo upload pipeline configuration
@@ -140,6 +141,10 @@ export function UppyPhotoSubmissionUpload({
);
if (profile?.banned) {
// Report ban evasion attempt
reportBanEvasionAttempt(user.id, 'photo_upload').catch(() => {
// Non-blocking - don't fail if alert fails
});
throw new Error('Account suspended. Contact support for assistance.');
}

View File

@@ -70,6 +70,36 @@ const createAuthenticatedSupabaseClient = (authHeader: string) => {
})
}
/**
* Report ban evasion attempts to system alerts
*/
async function reportBanEvasionToAlerts(
supabaseClient: any,
userId: string,
action: string,
requestId: string
): Promise<void> {
try {
await supabaseClient.rpc('create_system_alert', {
p_alert_type: 'ban_attempt',
p_severity: 'high',
p_message: `Banned user attempted image upload: ${action}`,
p_metadata: {
user_id: userId,
action,
request_id: requestId,
timestamp: new Date().toISOString()
}
});
} catch (error) {
// Non-blocking - log but don't fail the response
edgeLogger.warn('Failed to report ban evasion', {
error: error instanceof Error ? error.message : String(error),
requestId
});
}
}
// Apply strict rate limiting (5 requests/minute) to prevent abuse
const uploadRateLimiter = rateLimiters.strict;
@@ -164,7 +194,15 @@ serve(withRateLimit(async (req) => {
}
if (profile.banned) {
// Report ban evasion attempt (non-blocking)
await reportBanEvasionToAlerts(supabase, user.id, 'image_delete', tracking.requestId);
const duration = endRequest(tracking);
edgeLogger.warn('Banned user blocked from image deletion', {
userId: user.id,
requestId: tracking.requestId
});
return new Response(
JSON.stringify({
error: 'Account suspended',
@@ -375,7 +413,15 @@ serve(withRateLimit(async (req) => {
}
if (profile.banned) {
// Report ban evasion attempt (non-blocking)
await reportBanEvasionToAlerts(supabase, user.id, 'image_upload', tracking.requestId);
const duration = endRequest(tracking);
edgeLogger.warn('Banned user blocked from image upload', {
userId: user.id,
requestId: tracking.requestId
});
return new Response(
JSON.stringify({
error: 'Account suspended',

View File

@@ -0,0 +1,24 @@
-- Add rate_limit_violation to system_alerts alert_type check constraint
-- This enables tracking of rate limit violations in the admin dashboard
-- First, drop the existing check constraint
ALTER TABLE system_alerts
DROP CONSTRAINT IF EXISTS system_alerts_alert_type_check;
-- Recreate the constraint with the new value
ALTER TABLE system_alerts
ADD CONSTRAINT system_alerts_alert_type_check CHECK (alert_type IN (
'orphaned_images',
'stale_submissions',
'circular_dependency',
'validation_error',
'ban_attempt',
'upload_timeout',
'high_error_rate',
'rate_limit_violation',
'temp_ref_error',
'submission_queue_backlog',
'failed_submissions',
'high_ban_rate',
'slow_approval'
));