feat(v0.5.0): secure project previews and fix host UI compatibility

This commit is contained in:
Aisland
2026-10-27 23:09:34 +08:00
parent 6cb86b6c73
commit 56ffe0cd1c
30 changed files with 3202 additions and 1447 deletions
+23
View File
@@ -0,0 +1,23 @@
/** Use the host's current authentication service for every request, never a cached grant. */
export async function requestRejection(ctx: any, req: any): Promise<number | undefined> {
try {
const connection = typeof ctx.get === 'function' ? ctx.get('connection') : undefined
if (!connection) return 503
if (typeof connection.admit === 'function') {
const admission = await connection.admit(req)
if (!admission || typeof admission !== 'object') return 503
if ('rejection' in admission) return admission.rejection === 401 ? 401 : 403
const peer = admission.peer
// 0.2.1 has owner/non-owner principals. 0.2.0 has a single operator Peer.
if (peer?.principal?.kind === 'owner') return undefined
if (peer && peer === connection.operator && peer.principal === undefined) return undefined
return 403
}
} catch {}
// An unavailable or failed security service must not turn into public filesystem access.
return 503
}
export function rejectionText(status: number): string {
return status === 401 ? 'unauthorized' : status === 403 ? 'forbidden' : 'Host authentication unavailable'
}