Merge branch 'main' into fix/prod-restore-2026-09-29
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / security (push) Successful in 14s
masterplan-lock / check (pull_request) Successful in 12s
masterplan-lock / check (push) Successful in 22s
CI (SIAX Cloud) / security (pull_request) Successful in 30s
Security Scan (SIAX Cloud) / security (push) Successful in 25s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 47s
CI (SIAX Cloud) / integration (pull_request) Successful in 1m6s
CI (SIAX Cloud) / quality (push) Successful in 1m9s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m24s

This commit is contained in:
2026-11-02 07:37:20 +00:00
5 changed files with 48 additions and 5 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,4 +1,4 @@
# 0pt — cosign-signeringskedjan (2026-09-29)
Prod-imagen git.cloud.siax.io/sax3l/0pt:prod-cb01f948eb (sha256:32593df5dd1eeac061f6707f3292c4b9463816eb14856da07a6fb454cc275a51) är cosign-signerad
Prod-imagen git.cloud.siax.io/sax3l/0pt:prod-4f5a2ea865 (sha256:4e2afd83389d61a31673a97a90962a38d18cbf12c35e8cd2b3fdf6c3cbe9bf62) är cosign-signerad
med nyckelparet vars pubkey ligger här. Privata nyckeln raderad efter signering.
+2 -2
View File
@@ -1,4 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVjpLgpmI+gTZDt7zLhff6PaA2FmY
qpkzlm4x7znVVym/F0vEpNzbc0xQuQexYsNjMDYCgW3BMbZ2csEVRg/IwQ==
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEwNrAETFivagimW4jWWJUezFgvhqC
eUuv7eI3mmiEXuYcB1Uf4v2fv6EY5sgoGl/CY+4jFB2blu63a2gupNpOlQ==
-----END PUBLIC KEY-----
@@ -142,11 +142,18 @@ export class Doc0UploadClient {
) {
throw new Error('A trusted HTTPS DOC0 endpoint, service credential and valid upload limits are required');
}
// Keep the validated values even if the caller later changes its options object.
this.options = { ...options };
this.baseUrl = url.toString().replace(/\/+$/, '');
this.fetchImpl = options.fetchImpl ?? fetch;
}
async upload(input: Doc0UploadInput): Promise<Doc0UploadReceipt> {
if (!(input.bytes instanceof Uint8Array) || input.bytes.byteLength > this.options.maxBytes) {
throw new Error('Invalid DOC0 upload input');
}
// Bind the outbound request and receipt to the same immutable-by-caller input.
input = { ...input, bytes: new Uint8Array(input.bytes) };
const identity = prepareDoc0UploadIdentity(input);
if (identity.sourceSizeBytes > this.options.maxBytes) throw new Error('Invalid DOC0 upload input');
const expectedHash = identity.sourceSha256;
@@ -27,6 +27,43 @@ const receipt = {
};
describe('DOC0 upload client', () => {
it('validates the receipt against the original scope even if the caller mutates its input during dispatch', async () => {
const mutable = { ...input, bytes: new Uint8Array(input.bytes) };
const fetchImpl = async () => {
mutable.tenantId = 'tenant-b';
mutable.projectId = 'project-b';
return Response.json({ ...receipt,
document: { ...receipt.document, tenantId: 'tenant-b', projectId: 'project-b' },
currentVersion: { ...receipt.currentVersion, tenantId: 'tenant-b' },
}, { status: 201 });
};
const client = new Doc0UploadClient({ baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, fetchImpl });
await expect(client.upload(mutable)).rejects.toBeInstanceOf(Doc0UploadOutcomeUnknownError);
});
it('accepts a matching receipt for the bytes and scope actually dispatched', async () => {
const mutable = { ...input, bytes: new Uint8Array(input.bytes) };
const fetchImpl = async (_url: string | URL | Request, init?: RequestInit) => {
mutable.tenantId = 'tenant-b';
mutable.bytes.fill(0);
const sentFile = (init?.body as FormData).get('file') as Blob;
expect(await sentFile.text()).toBe('source bytes');
return Response.json(receipt, { status: 201 });
};
const client = new Doc0UploadClient({ baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, fetchImpl });
await expect(client.upload(mutable)).resolves.toMatchObject({ documentId: 'doc-a' });
});
it('pins validated client configuration rather than trusting later mutations', async () => {
const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
expect(new Headers(init?.headers).get('authorization')).toBe('Bearer test');
return Response.json(receipt, { status: 201 });
});
const config = { baseUrl: 'https://doc0.test', serviceToken: 'test', maxBytes: 100, timeoutMs: 1000, fetchImpl };
const client = new Doc0UploadClient(config);
config.serviceToken = 'changed';
config.maxBytes = 1;
config.timeoutMs = 0;
await expect(client.upload(input)).resolves.toMatchObject({ documentId: 'doc-a' });
});
it('sends real bytes and validates a tenant-scoped checksum-bound receipt', async () => {
const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
expect(new Headers(init?.headers).get('x-tenant-id')).toBe('tenant-a');