fix(cloud): harden edge gateways, api-server ssrf, supabase fail-closed quota, and web/admin lifecycle
This commit is contained in:
parent
2a009e421a
commit
c68e81e0aa
46 changed files with 2553 additions and 294 deletions
|
|
@ -6,6 +6,8 @@
|
|||
// (team invites, transcription completion, billing) never left the queue. This
|
||||
// worker drains them on a cron schedule.
|
||||
|
||||
import { parsePublicHttpsOrigin } from './origin-policy.ts'
|
||||
|
||||
export interface PushDrainEnv {
|
||||
SUPABASE_URL?: string
|
||||
SUPABASE_SERVICE_ROLE_KEY?: string
|
||||
|
|
@ -35,17 +37,21 @@ export async function drainPushDispatches(
|
|||
env: PushDrainEnv,
|
||||
fetchImpl: typeof fetch = fetch,
|
||||
): Promise<PushDrainResult> {
|
||||
const baseUrl = env.SUPABASE_URL?.trim().replace(/\/+$/, '') ?? ''
|
||||
const rawUrl = env.SUPABASE_URL?.trim().replace(/\/+$/, '') ?? ''
|
||||
const serviceRoleKey = env.SUPABASE_SERVICE_ROLE_KEY?.trim() ?? ''
|
||||
if (!baseUrl || serviceRoleKey.length < 20) {
|
||||
if (!rawUrl || serviceRoleKey.length < 20) {
|
||||
return { ok: false, status: 503, error: 'push_drain_not_configured' }
|
||||
}
|
||||
const parsedBaseUrl = parsePublicHttpsOrigin(rawUrl)
|
||||
if (!parsedBaseUrl) {
|
||||
return { ok: false, status: 503, error: 'push_drain_invalid_config' }
|
||||
}
|
||||
|
||||
const limit = resolveBatchLimit(env.PUSH_DRAIN_BATCH_LIMIT)
|
||||
let response: Response
|
||||
try {
|
||||
response = await fetchImpl(
|
||||
`${baseUrl}/functions/v1/send-push?mode=drain&limit=${limit}`,
|
||||
`${parsedBaseUrl.origin}/functions/v1/send-push?mode=drain&limit=${limit}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -53,6 +59,7 @@ export async function drainPushDispatches(
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: '{}',
|
||||
redirect: 'manual',
|
||||
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue