feat: strengthen P0 security and operations

This commit is contained in:
2026-08-01 11:20:02 +08:00
parent f776056834
commit 84c2b0b21d
77 changed files with 24185 additions and 355 deletions

View File

@@ -6,6 +6,7 @@ using Tiku.Application.Security;
using Tiku.Application.Commerce;
using Tiku.Application.Content;
using Tiku.Application.Growth;
using Tiku.Application.Jobs;
using Tiku.Application.Points;
using Tiku.Application.PlatformAdmin;
using Tiku.Application.PlatformBilling;
@@ -51,6 +52,20 @@ public sealed class ExceptionHandlingMiddleware(
return;
}
if (exception is TenantLifecycleException lifecycleException)
{
var status = lifecycleException.Code switch
{
"tenant_not_found" => StatusCodes.Status404NotFound,
"tenant_export_not_ready" => StatusCodes.Status409Conflict,
"tenant_archive_blocked" or "tenant_not_archived" or
"tenant_owner_target_not_active_member" or "tenant_owner_unchanged" => StatusCodes.Status409Conflict,
_ => StatusCodes.Status400BadRequest
};
await WriteProblemAsync(context, lifecycleException.Message, status, lifecycleException.Code);
return;
}
if (exception is BrowserOriginException)
{
await WriteProblemAsync(context, exception.Message, StatusCodes.Status403Forbidden, "browser_origin_rejected");
@@ -69,6 +84,22 @@ public sealed class ExceptionHandlingMiddleware(
return;
}
if (exception is BackgroundJobException backgroundJobException)
{
var status = backgroundJobException.Code switch
{
"background_job_not_found" => StatusCodes.Status404NotFound,
"background_job_not_cancellable" or "background_job_not_retryable" => StatusCodes.Status409Conflict,
_ => StatusCodes.Status400BadRequest
};
await WriteProblemAsync(
context,
backgroundJobException.Message,
status,
backgroundJobException.Code);
return;
}
if (exception is TenantContextConflictException)
{
await WriteProblemAsync(
@@ -417,6 +448,8 @@ public sealed class ExceptionHandlingMiddleware(
var status = exception.Code switch
{
"tenant_access_denied" => StatusCodes.Status403Forbidden,
"auth_session_not_found" => StatusCodes.Status404NotFound,
"current_auth_session_cannot_be_revoked" => StatusCodes.Status409Conflict,
"sms_rate_limited" => StatusCodes.Status429TooManyRequests,
"auth_provider_not_configured" => StatusCodes.Status503ServiceUnavailable,
"auth_security_unavailable" => StatusCodes.Status503ServiceUnavailable,