fix: secure document upload transport
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 4s
Security Scan (SIAX Cloud) / security (push) Successful in 13s
CI (SIAX Cloud) / security (push) Successful in 24s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 23s
CI (SIAX Cloud) / security (pull_request) Successful in 29s
CI (SIAX Cloud) / integration (pull_request) Successful in 35s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m5s
CI (SIAX Cloud) / quality (push) Successful in 1m13s

This commit is contained in:
2026-11-02 02:09:45 +01:00
parent e580916535
commit 70b92e2fea
2 changed files with 23 additions and 4 deletions
+11 -4
View File
@@ -29,6 +29,7 @@ export interface Doc0UploadReceipt {
*/
export class Doc0UploadClient {
private readonly fetchImpl: typeof fetch;
private readonly baseUrl: string;
constructor(
private readonly options: {
baseUrl: string;
@@ -38,14 +39,19 @@ export class Doc0UploadClient {
fetchImpl?: typeof fetch;
},
) {
let url: URL;
try { url = new URL(options.baseUrl); }
catch { throw new Error('A trusted HTTPS DOC0 endpoint is required'); }
if (
!options.baseUrl.trim() ||
url.protocol !== 'https:' || url.username || url.password || url.search || url.hash ||
!options.serviceToken.trim() ||
!Number.isSafeInteger(options.maxBytes) ||
options.maxBytes <= 0
options.maxBytes <= 0 ||
(options.timeoutMs !== undefined && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1_000 || options.timeoutMs > 300_000))
) {
throw new Error('DOC0 endpoint, service credential and upload limit are required');
throw new Error('A trusted HTTPS DOC0 endpoint, service credential and valid upload limits are required');
}
this.baseUrl = url.toString().replace(/\/+$/, '');
this.fetchImpl = options.fetchImpl ?? fetch;
}
@@ -81,8 +87,9 @@ export class Doc0UploadClient {
}),
);
body.set('file', new Blob([new Uint8Array(input.bytes)], { type: input.mimeType }), input.filename);
const response = await this.fetchImpl(`${this.options.baseUrl.replace(/\/+$/, '')}/v1/doc0/documents`, {
const response = await this.fetchImpl(`${this.baseUrl}/v1/doc0/documents`, {
method: 'POST',
redirect: 'error',
headers: {
authorization: `Bearer ${this.options.serviceToken}`,
'x-tenant-id': input.tenantId,