CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 10s
CI (SIAX Cloud) / sonar (pull_request) Skipped
Security Scan (SIAX Cloud) / security (push) Successful in 13s
masterplan-lock / check (pull_request) Successful in 7s
CI (SIAX Cloud) / security (push) Successful in 26s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 19s
CI (SIAX Cloud) / quality (push) Successful in 1m9s
CI (SIAX Cloud) / quality (pull_request) Successful in 2m26s
CI (SIAX Cloud) / integration (pull_request) Successful in 2m33s
- POST /api/0pt/documents/upload: real multipart bytes into DOC0 through the durable attempt journal and the existing coordinator; verified tenant/actor only, project authorization fail-closed. - POST /api/0pt/documents/structure: DOC0 segments -> INF0 -> evidence-bound validation -> optional JSON/CSV export, with credit reserve/settle. - Credits: balance, server-owned price book, Stripe Checkout and idempotent webhook reconciliation via a Stripe re-read of session + payment intent. - /portal/dokument and /portal/krediter: SIAX-styled workspace. - @siax/access: universal, framework-neutral OpenFGA project relationship primitive reusable by DOC0/N0D/other products. - Readiness: real Redis PING probe instead of presence-only; queue is now a live dependency when configured. - Dockerfile: copy every workspace manifest so --frozen-lockfile works. - Format/build hygiene: .prettierignore, .worktrees ignored, valid manifest YAML.
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
/**
|
|
* Verified request scope for customer-facing 0pt routes.
|
|
*
|
|
* Middleware (`middleware.ts`) performs real Zitadel Bearer verification and
|
|
* forwards the verified subject/tenant only when a principal was verified.
|
|
* Customer routes must NOT fall back to client-supplied tenant/actor values:
|
|
* that fallback exists only for the explicit local-development mode, and even
|
|
* there this helper requires an explicit dev tenant header.
|
|
*/
|
|
import { NextResponse, type NextRequest } from 'next/server';
|
|
import { VERIFIED_TENANT_HEADER } from './tenant-guard';
|
|
|
|
export const VERIFIED_SUBJECT_HEADER = 'x-0pt-verified-sub';
|
|
/** Dev-only header (AUTH_ENFORCE=false) so local flows still have a scope. */
|
|
export const DEV_TENANT_HEADER = 'x-0pt-dev-tenant';
|
|
export const DEV_SUBJECT_HEADER = 'x-0pt-dev-subject';
|
|
|
|
const idPattern = /^[\x21-\x7e]{1,256}$/;
|
|
|
|
export interface VerifiedScope {
|
|
tenantId: string;
|
|
actorId: string;
|
|
}
|
|
|
|
function devMode(): boolean {
|
|
return process.env.AUTH_ENFORCE === 'false' && process.env.NODE_ENV !== 'production';
|
|
}
|
|
|
|
export function resolveVerifiedScope(
|
|
request: NextRequest,
|
|
): { scope: VerifiedScope } | { response: NextResponse } {
|
|
const tenantId = request.headers.get(VERIFIED_TENANT_HEADER);
|
|
const actorId = request.headers.get(VERIFIED_SUBJECT_HEADER);
|
|
if (tenantId && actorId && idPattern.test(tenantId) && idPattern.test(actorId)) {
|
|
return { scope: { tenantId, actorId } };
|
|
}
|
|
if (devMode()) {
|
|
const devTenant = request.headers.get(DEV_TENANT_HEADER);
|
|
const devActor = request.headers.get(DEV_SUBJECT_HEADER);
|
|
if (devTenant && devActor && idPattern.test(devTenant) && idPattern.test(devActor)) {
|
|
return { scope: { tenantId: devTenant, actorId: devActor } };
|
|
}
|
|
}
|
|
return {
|
|
response: NextResponse.json(
|
|
{
|
|
error: 'OPT_UNAUTHENTICATED',
|
|
message: 'A verified tenant and subject are required',
|
|
},
|
|
{ status: 401 },
|
|
),
|
|
};
|
|
}
|
|
|
|
export function isValidScopeId(value: unknown): value is string {
|
|
return typeof value === 'string' && idPattern.test(value);
|
|
}
|