fix(cloud): harden edge gateways, api-server ssrf, supabase fail-closed quota, and web/admin lifecycle

This commit is contained in:
Yun Chan 2026-11-14 15:10:32 +09:00
parent 2a009e421a
commit c68e81e0aa
46 changed files with 2553 additions and 294 deletions

View file

@ -259,3 +259,30 @@ Deno.test('non-multipart body fails closed with 400 instead of 500', async () =>
assertEquals(await response.json(), { error: 'invalid_multipart_body' }, 'body')
assertEquals(h.events, [], 'no quota or provider work')
})
Deno.test('sttProxy_초과ContentLength헤더_본문파싱전에413으로차단한다', async () => {
const h = harness([fakeProvider('groq', OK)])
let bodyRead = false
const req = new Request('http://localhost/stt-proxy', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data; boundary=x',
'Content-Length': String(30 * 1024 * 1024),
},
body: new ReadableStream(
{
pull() {
bodyRead = true
return Promise.reject(new Error('body must not be read when Content-Length exceeds cap'))
},
},
new CountQueuingStrategy({ highWaterMark: 0 }),
),
})
const response = await h.handler(req)
assertEquals(response.status, 413, 'oversized Content-Length returns 413')
assertEquals(await response.json(), { error: 'audio_too_large' }, 'fixed size error code')
assertEquals(bodyRead, false, 'request stream must not be pulled')
assertEquals(req.bodyUsed, false, 'request body must remain unread')
assertEquals(h.events, [], 'no quota or provider work')
})

View file

@ -18,6 +18,7 @@ import { handleCorsPreflightRequest } from '../_shared/cors.ts'
import { createStatusJsonResponder } from '../_shared/json-response.ts'
import {
type DictionaryHints,
MAX_STT_AUDIO_BYTES,
type NormalizedSttResult,
type SttFailureCode,
SttInputError,
@ -118,6 +119,7 @@ export async function runSttChain(
}
const json = createStatusJsonResponder()
const MAX_STT_MULTIPART_BYTES = MAX_STT_AUDIO_BYTES + 1024 * 1024
export function createSttProxyHandler(deps: SttProxyDeps): (req: Request) => Promise<Response> {
const { quota, logger } = deps
@ -137,7 +139,15 @@ export function createSttProxyHandler(deps: SttProxyDeps): (req: Request) => Pro
if (!auth.ok) return auth.response
const user = auth.user
// 2) input
// 2) input (reject oversized Content-Length before buffering multipart body)
const rawContentLength = req.headers.get('content-length')
if (rawContentLength !== null) {
const declaredBytes = Number(rawContentLength.trim())
if (Number.isFinite(declaredBytes) && declaredBytes > MAX_STT_MULTIPART_BYTES) {
return json(413, { error: 'audio_too_large' })
}
}
let formData: FormData
try {
formData = await req.formData()