@sentropic/artifacts 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +15 -14
- package/dist/adapters/s3-uploads.d.ts +8 -7
- package/dist/adapters/s3-uploads.js +9 -17
- package/dist/http.js +83 -20
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/dist/server/management.js +10 -5
- package/dist/server/ports.d.ts +7 -0
- package/dist/server/ports.js +7 -0
- package/dist/server/templates.js +10 -9
- package/dist/server/upload-page.d.ts +0 -1
- package/dist/server/upload-page.js +1 -3
- package/dist/server/uploads.d.ts +27 -19
- package/dist/server/uploads.js +82 -47
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.16
|
|
4
|
+
|
|
5
|
+
- Upload channel integrity, fail-closed (immo preprod, OVH S3 403): the
|
|
6
|
+
presigned PUT no longer announces `x-amz-checksum-sha256`. The digest is
|
|
7
|
+
declared at commit, so the checksum header could never be signed at
|
|
8
|
+
`create_upload` time, and strict S3 implementations refuse presigned PUTs
|
|
9
|
+
carrying an unsigned `x-amz-*` header (`AccessDenied`, headers present but
|
|
10
|
+
not signed). `create_upload` now returns exactly the signed header set
|
|
11
|
+
(`content-type` + exact `content-length`) in `requiredHeaders`, with no
|
|
12
|
+
`checksumHeader` field; the client (agent SDK/CI and the browser upload
|
|
13
|
+
page) sends exactly those headers and nothing else. Signing the checksum
|
|
14
|
+
instead would have required the digest at create time, i.e. a change to the
|
|
15
|
+
frozen `artifacts_create_upload` input schema; it also depends on S3
|
|
16
|
+
checksum support that the repo's minio double does not guarantee, while a
|
|
17
|
+
plain PUT works on OVH and minio alike (immo verified the headerless PUT
|
|
18
|
+
returns 200 on preprod).
|
|
19
|
+
- `commit_upload` no longer trusts the declared digest alone: it re-reads the
|
|
20
|
+
staged bytes and re-verifies size, SHA-256 and MIME server-side, and any
|
|
21
|
+
mismatch now refuses with a typed `UploadVerificationError` (mapped to
|
|
22
|
+
`verification_failed` at the HTTP layer with the same public reasons),
|
|
23
|
+
deletes the staged object, closes the session, and pins nothing — a
|
|
24
|
+
poisoned upload can never be retried into a release. The CAS read-back
|
|
25
|
+
mismatch path deletes the suspect blob too.
|
|
26
|
+
- No MCP tool definition changes (the 17 pre-existing definitions stay
|
|
27
|
+
byte-identical); only the `create_upload` response shape loses the
|
|
28
|
+
`checksumHeader` field. Stays in `0.2.x` (cluster-mesh peer `>=0.2.0
|
|
29
|
+
<0.3.0`).
|
|
30
|
+
|
|
31
|
+
## 0.2.15
|
|
32
|
+
|
|
33
|
+
- R1: every model-visible userRef projection emits the opaque `unknown` value
|
|
34
|
+
when the directory entry is missing instead of falling back to the raw
|
|
35
|
+
internal id (`sub`): `projectUserRef`, `list_access` grants and owner,
|
|
36
|
+
the `set_access` receipt, and the `list_versions` v1 author (plus the v2
|
|
37
|
+
`authorPrincipalId`). No MCP tool definition changes.
|
|
38
|
+
- R5: `assertShareable` enforces the approved-principal gate on `grant` only;
|
|
39
|
+
`revoke` stays allowed for dormant (suspended or deleted) principals as the
|
|
40
|
+
expected cleanup step. Revoking an absent grant is a no-op success.
|
|
41
|
+
|
|
3
42
|
## 0.2.14
|
|
4
43
|
|
|
5
44
|
- Add a durable local SQLite adapter set behind the new `./sqlite` subpath export:
|
package/README.md
CHANGED
|
@@ -255,20 +255,21 @@ Large or binary files never travel through the model or the MCP payload:
|
|
|
255
255
|
`artifacts/<scope>/staging/<uploadId>` (URL expiry ≤ 10 minutes). A SigV4
|
|
256
256
|
presigned PUT cannot carry a content-length range, so the signature binds the
|
|
257
257
|
content type and the exact declared `Content-Length` (`maxSize`, itself capped
|
|
258
|
-
by the release per-file limit and the 16 MiB server ceiling)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
with exactly the returned `requiredHeaders
|
|
262
|
-
capped (server maximum 8); stale
|
|
263
|
-
in `gc.ts` (`createUploadSweeper`,
|
|
264
|
-
`artifacts_commit_upload` then declares
|
|
265
|
-
server re-reads the staged object once
|
|
266
|
-
MIME (magic bytes, strict UTF-8, SVG
|
|
267
|
-
promoting the bytes to the digest-addressed
|
|
268
|
-
(`artifacts/<scope>/blobs/sha256/<hex>`) through the bounded blob
|
|
269
|
-
read-back verification, and pinning them with reason
|
|
270
|
-
A wrong size or digest is refused with
|
|
271
|
-
|
|
258
|
+
by the release per-file limit and the 16 MiB server ceiling), and nothing else:
|
|
259
|
+
no checksum header is signed or announced, because strict S3 implementations
|
|
260
|
+
(OVH) refuse presigned PUTs carrying an unsigned `x-amz-*` header. The local
|
|
261
|
+
agent performs the PUT with exactly the returned `requiredHeaders` and no other
|
|
262
|
+
header. Open sessions per principal are capped (server maximum 8); stale
|
|
263
|
+
sessions are expired by the enforced sweeper in `gc.ts` (`createUploadSweeper`,
|
|
264
|
+
driven by `uploads.expires_at`). `artifacts_commit_upload` then declares
|
|
265
|
+
`{path, mimeType, digest, size}`; the server re-reads the staged object once
|
|
266
|
+
and re-verifies size, SHA-256 digest and MIME (magic bytes, strict UTF-8, SVG
|
|
267
|
+
script/handler/href rules) before promoting the bytes to the digest-addressed
|
|
268
|
+
blob store (`artifacts/<scope>/blobs/sha256/<hex>`) through the bounded blob
|
|
269
|
+
pool with read-back verification, and pinning them with reason
|
|
270
|
+
`upload:<uploadId>`. A wrong size or digest is refused with
|
|
271
|
+
`verification_failed` (422): the staged object is deleted, the session is
|
|
272
|
+
closed, and nothing is pinned; commit alone creates no release. `artifacts_publish_bundle` finally
|
|
272
273
|
publishes one atomic release from inline `files` and/or `assets` (each asset
|
|
273
274
|
`{path, uploadId}` or `{path, digest, size, mimeType}` referencing an
|
|
274
275
|
already-pinned blob of the same scope); `expectedCurrentReleaseId` is always
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*
|
|
8
8
|
* UploadSignerPort over `@aws-sdk/s3-request-presigner`: the signature binds
|
|
9
9
|
* content-type and the EXACT Content-Length (a SigV4 presigned PUT cannot
|
|
10
|
-
* carry a content-length range — review finding 3),
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* carry a content-length range — review finding 3), and nothing else. No
|
|
11
|
+
* checksum header is signed or announced: the digest is declared at commit
|
|
12
|
+
* and strict S3 implementations (OVH) refuse presigned PUTs carrying unsigned
|
|
13
|
+
* `x-amz-*` headers. The returned headers are exactly the signed set. The
|
|
14
|
+
* client (endpoint, region, credentials, path style) is built by the host and
|
|
15
|
+
* injected — this module never reads env or connects.
|
|
15
16
|
*/
|
|
16
17
|
import { type S3Client } from '@aws-sdk/client-s3';
|
|
17
18
|
import { type StagingStore, type UploadSignerPort } from '../server/uploads.js';
|
|
@@ -27,7 +28,7 @@ export interface S3UploadSignerOptions {
|
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Create a presigned-PUT signer over an injected client. The signature binds
|
|
30
|
-
* content-type + exact content-length (declared size) and
|
|
31
|
-
*
|
|
31
|
+
* content-type + exact content-length (declared size) and nothing else; the
|
|
32
|
+
* returned headers are exactly the signed set (no `x-amz-*` header).
|
|
32
33
|
*/
|
|
33
34
|
export declare function createS3UploadSigner(options: S3UploadSignerOptions): UploadSignerPort;
|
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
*
|
|
8
8
|
* UploadSignerPort over `@aws-sdk/s3-request-presigner`: the signature binds
|
|
9
9
|
* content-type and the EXACT Content-Length (a SigV4 presigned PUT cannot
|
|
10
|
-
* carry a content-length range — review finding 3),
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* carry a content-length range — review finding 3), and nothing else. No
|
|
11
|
+
* checksum header is signed or announced: the digest is declared at commit
|
|
12
|
+
* and strict S3 implementations (OVH) refuse presigned PUTs carrying unsigned
|
|
13
|
+
* `x-amz-*` headers. The returned headers are exactly the signed set. The
|
|
14
|
+
* client (endpoint, region, credentials, path style) is built by the host and
|
|
15
|
+
* injected — this module never reads env or connects.
|
|
15
16
|
*/
|
|
16
17
|
import { DeleteObjectCommand, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, } from '@aws-sdk/client-s3';
|
|
17
18
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
18
|
-
import { assertStagingKey, assertStagingPrefix,
|
|
19
|
+
import { assertStagingKey, assertStagingPrefix, } from '../server/uploads.js';
|
|
19
20
|
/** Create an S3-backed staging store over an injected client (no env reads). */
|
|
20
21
|
export function createS3StagingStore(options) {
|
|
21
22
|
return {
|
|
@@ -63,8 +64,8 @@ export function createS3StagingStore(options) {
|
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Create a presigned-PUT signer over an injected client. The signature binds
|
|
66
|
-
* content-type + exact content-length (declared size) and
|
|
67
|
-
*
|
|
67
|
+
* content-type + exact content-length (declared size) and nothing else; the
|
|
68
|
+
* returned headers are exactly the signed set (no `x-amz-*` header).
|
|
68
69
|
*/
|
|
69
70
|
export function createS3UploadSigner(options) {
|
|
70
71
|
return {
|
|
@@ -73,22 +74,14 @@ export function createS3UploadSigner(options) {
|
|
|
73
74
|
if (!Number.isSafeInteger(input.contentLength) || input.contentLength < 0) {
|
|
74
75
|
throw new Error('invalid signed content-length');
|
|
75
76
|
}
|
|
76
|
-
const checksumHeader = input.checksumSha256 === undefined
|
|
77
|
-
? undefined
|
|
78
|
-
: checksumHeaderValue(input.checksumSha256);
|
|
79
77
|
const command = new PutObjectCommand({
|
|
80
78
|
Bucket: options.bucket,
|
|
81
79
|
Key: input.key,
|
|
82
80
|
ContentType: input.contentType,
|
|
83
81
|
ContentLength: input.contentLength,
|
|
84
|
-
...(checksumHeader === undefined ? {} : { ChecksumSHA256: checksumHeader }),
|
|
85
82
|
});
|
|
86
83
|
const url = await getSignedUrl(options.client, command, {
|
|
87
84
|
expiresIn: input.expiresInSeconds,
|
|
88
|
-
// keep the checksum a signed header (x-amz-* headers are hoisted to the
|
|
89
|
-
// query by default); content-type/content-length are never hoisted and
|
|
90
|
-
// are therefore always signed headers the client must send exactly.
|
|
91
|
-
unhoistableHeaders: new Set(['x-amz-checksum-sha256']),
|
|
92
85
|
});
|
|
93
86
|
return {
|
|
94
87
|
url,
|
|
@@ -96,7 +89,6 @@ export function createS3UploadSigner(options) {
|
|
|
96
89
|
headers: {
|
|
97
90
|
'content-type': input.contentType,
|
|
98
91
|
'content-length': String(input.contentLength),
|
|
99
|
-
...(checksumHeader === undefined ? {} : { 'x-amz-checksum-sha256': checksumHeader }),
|
|
100
92
|
},
|
|
101
93
|
expiresAt: new Date(Date.now() + input.expiresInSeconds * 1000).toISOString(),
|
|
102
94
|
};
|
package/dist/http.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Selected HTTP control surface over the authorized atomic services. */
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { parseManifest } from './codecs.js';
|
|
3
|
+
import { canonicalManifest, manifestDigest, parseManifest } from './codecs.js';
|
|
4
4
|
import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './profile/index.js';
|
|
5
5
|
import { createArtifactCommand } from './server/command-identity.js';
|
|
6
6
|
import { createGuardedEnsureService } from './server/service.js';
|
|
7
7
|
import { assertArtifactReplayMigration } from './server/idempotency.js';
|
|
8
|
-
import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy } from './server/ports.js';
|
|
8
|
+
import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy, UNKNOWN_USER_REF } from './server/ports.js';
|
|
9
9
|
import { createGuardedPublicationService } from './server/publication.js';
|
|
10
10
|
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_SOURCE_FILES, SERVER_MAX_SOURCE_INLINE_BYTES, SERVER_MAX_SOURCE_TOTAL_BYTES, SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL } from './server/publication-limits.js';
|
|
11
11
|
import { releaseBudget } from './profile/validation.js';
|
|
12
|
-
import { commitStagedUpload, createUploadService, STAGED_FILE_TTL_MS, stagedFileExpired } from './server/uploads.js';
|
|
12
|
+
import { commitStagedUpload, createUploadService, STAGED_FILE_TTL_MS, stagedFileExpired, UploadVerificationError } from './server/uploads.js';
|
|
13
13
|
import { createHmacUploadPageCookieSigner, createMemoryUploadPageStore, createUploadPageService } from './server/upload-page.js';
|
|
14
14
|
import { accessModeOf, evaluateGrant } from './server/access.js';
|
|
15
15
|
import { assertConsentScopeId } from './server/consent.js';
|
|
@@ -325,7 +325,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
325
325
|
async function projectUserRef(internalId, storageScopeId) {
|
|
326
326
|
if (!deps.directory)
|
|
327
327
|
return internalId;
|
|
328
|
-
return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ??
|
|
328
|
+
return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? UNKNOWN_USER_REF;
|
|
329
329
|
}
|
|
330
330
|
async function projectSummary(summary, storageScopeId) {
|
|
331
331
|
if (!deps.directory)
|
|
@@ -431,15 +431,47 @@ export function createHttpArtifactApp(deps) {
|
|
|
431
431
|
? { base64: Buffer.from(file.bytes).toString('base64'), encoding: 'base64' }
|
|
432
432
|
: { text: file.text, encoding: 'utf8' }) }));
|
|
433
433
|
await visible(artifactId, invocation, 'source');
|
|
434
|
+
const projectedManifest = await projectManifestForOutput(release.manifest, invocation.storageScopeId);
|
|
434
435
|
const failure = { ...outcome.failure, conflict: { ...conflict, currentSource: {
|
|
435
|
-
artifactId, releaseId: release.releaseId, digest:
|
|
436
|
+
artifactId, releaseId: release.releaseId, digest: parseManifest(projectedManifest).digest ?? conflict.currentDigest,
|
|
437
|
+
manifest: projectedManifest,
|
|
436
438
|
files, sourceRef: null, guideRef: API_GUIDE_REF, ...deps.publicationUrls?.(artifactId, release.releaseId),
|
|
437
439
|
} } };
|
|
438
440
|
Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
|
|
439
441
|
return { ok: false, failure: Object.freeze(failure) };
|
|
440
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* R1 output-boundary projection for the release manifest embedded in
|
|
445
|
+
* publish/revert/bundle receipts. Storage keeps the raw internal `ownerId`
|
|
446
|
+
* (the manifest bytes are content-addressed); only this model-visible copy
|
|
447
|
+
* carries the opaque `userRef` (or `UNKNOWN_USER_REF` when the directory
|
|
448
|
+
* has no entry). Without a directory port the stored bytes pass through
|
|
449
|
+
* unchanged (G1 legacy behaviour).
|
|
450
|
+
*/
|
|
451
|
+
async function projectManifestForOutput(rawManifest, storageScopeId) {
|
|
452
|
+
if (!deps.directory)
|
|
453
|
+
return rawManifest;
|
|
454
|
+
let parsed;
|
|
455
|
+
try {
|
|
456
|
+
parsed = JSON.parse(rawManifest);
|
|
457
|
+
}
|
|
458
|
+
catch {
|
|
459
|
+
return rawManifest;
|
|
460
|
+
}
|
|
461
|
+
const rawOwner = parsed.ownerId;
|
|
462
|
+
if (typeof rawOwner !== 'string')
|
|
463
|
+
return rawManifest;
|
|
464
|
+
const projected = (await deps.directory.describePrincipal(storageScopeId, rawOwner))?.userRef
|
|
465
|
+
?? UNKNOWN_USER_REF;
|
|
466
|
+
if (projected === rawOwner)
|
|
467
|
+
return rawManifest;
|
|
468
|
+
const { digest: _drop, ...body } = parsed;
|
|
469
|
+
void _drop;
|
|
470
|
+
const nextDigest = manifestDigest({ ...body, ownerId: projected });
|
|
471
|
+
return canonicalManifest({ ...body, ownerId: projected, digest: nextDigest });
|
|
472
|
+
}
|
|
441
473
|
/** Shared guarded-commit response for publish and revert (same commit path, same receipt shape). */
|
|
442
|
-
function commitOutcome(outcome, artifactId, meta, setCommitState) {
|
|
474
|
+
async function commitOutcome(outcome, artifactId, meta, setCommitState, storageScopeId) {
|
|
443
475
|
if (!outcome.ok) {
|
|
444
476
|
const failure = { ...outcome.failure, kind: 'operational' };
|
|
445
477
|
Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
|
|
@@ -450,11 +482,12 @@ export function createHttpArtifactApp(deps) {
|
|
|
450
482
|
if (typeof receipt.releaseId !== 'string' || typeof receipt.manifest !== 'string') {
|
|
451
483
|
throw new Error('invalid publication receipt');
|
|
452
484
|
}
|
|
485
|
+
const manifest = await projectManifestForOutput(receipt.manifest, storageScopeId);
|
|
453
486
|
return { ...outcome, result: { status: 201, body: {
|
|
454
|
-
artifactId, releaseId: receipt.releaseId, manifest
|
|
487
|
+
artifactId, releaseId: receipt.releaseId, manifest,
|
|
455
488
|
previousReleaseId: receipt.previousReleaseId ?? null, updatedAt: receipt.updatedAt ?? null,
|
|
456
489
|
...(typeof receipt.revertedFromReleaseId === 'string' ? { revertedFromReleaseId: receipt.revertedFromReleaseId } : {}),
|
|
457
|
-
digest: parseManifest(
|
|
490
|
+
digest: parseManifest(manifest).digest,
|
|
458
491
|
...deps.publicationUrls?.(artifactId, receipt.releaseId), ...(receipt.metadata ?? meta ?? {}),
|
|
459
492
|
} } };
|
|
460
493
|
}
|
|
@@ -550,7 +583,11 @@ export function createHttpArtifactApp(deps) {
|
|
|
550
583
|
maxInlineBytes: sourceOp?.limits['sourceInlineFileBytesMax'] ?? SERVER_MAX_SOURCE_INLINE_BYTES,
|
|
551
584
|
maxTotalBytes: sourceOp?.limits['sourceTotalBytesMax'] ?? SERVER_MAX_SOURCE_TOTAL_BYTES,
|
|
552
585
|
}, normalized);
|
|
553
|
-
|
|
586
|
+
const projectedSourceManifest = await projectManifestForOutput(result.manifest, invocation.storageScopeId);
|
|
587
|
+
const projectedSource = projectedSourceManifest === result.manifest ? result
|
|
588
|
+
: { ...result, manifest: projectedSourceManifest,
|
|
589
|
+
digest: parseManifest(projectedSourceManifest).digest ?? result.digest };
|
|
590
|
+
return { ok: true, result: { status: 200, body: projectedSource }, invocationId: invocation.invocationId,
|
|
554
591
|
commitState: 'not_committed', replayed: false };
|
|
555
592
|
}
|
|
556
593
|
if (capability === 'artifacts_list_assets') {
|
|
@@ -685,7 +722,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
685
722
|
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
686
723
|
const replay = await publication.replayFinalized(input);
|
|
687
724
|
if (replay !== undefined)
|
|
688
|
-
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
725
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
689
726
|
profile.validate(capability, args, request.idempotencyKey);
|
|
690
727
|
let files;
|
|
691
728
|
let source;
|
|
@@ -727,7 +764,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
727
764
|
const outcome = await publication.publishFinalized({
|
|
728
765
|
...input, source, profile: releaseProfile, files,
|
|
729
766
|
});
|
|
730
|
-
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
767
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
731
768
|
return await conflictSource(committed, normalized, invocation);
|
|
732
769
|
}
|
|
733
770
|
if (capability === 'artifacts_create_upload') {
|
|
@@ -759,7 +796,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
759
796
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
760
797
|
result: { status: 201, body: { uploadId: created.uploadId, uploadUrl: created.uploadUrl,
|
|
761
798
|
method: created.method, expiresAt: created.expiresAt, maxSize: created.maxSize,
|
|
762
|
-
requiredHeaders: created.requiredHeaders
|
|
799
|
+
requiredHeaders: created.requiredHeaders } } };
|
|
763
800
|
}
|
|
764
801
|
if (capability === 'artifacts_commit_upload') {
|
|
765
802
|
const artifactId = normalized.artifactId;
|
|
@@ -788,8 +825,22 @@ export function createHttpArtifactApp(deps) {
|
|
|
788
825
|
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
789
826
|
publicDetails: { upload: { reason: 'staged_budget' } } });
|
|
790
827
|
}
|
|
828
|
+
if (cause instanceof UploadVerificationError) {
|
|
829
|
+
const sessionReasons = ['unknown_upload', 'session_not_open', 'session_expired'];
|
|
830
|
+
if (sessionReasons.includes(cause.reason)) {
|
|
831
|
+
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
832
|
+
throw new ArtifactOperationError('verification_failed', { cause,
|
|
833
|
+
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
834
|
+
}
|
|
835
|
+
if (cause.reason === 'staged_missing') {
|
|
836
|
+
throw new ArtifactOperationError('verification_failed', { publicDetails: { upload: { reason: 'staged object missing' } } });
|
|
837
|
+
}
|
|
838
|
+
throw new ArtifactOperationError('verification_failed', { cause,
|
|
839
|
+
publicDetails: { upload: { reason: 'size/digest/MIME mismatch' } } });
|
|
840
|
+
}
|
|
841
|
+
// Legacy plain-error fallback (e.g. a session store racing a
|
|
842
|
+
// delete between commit steps): same public reasons as before.
|
|
791
843
|
if (cause instanceof Error && (/unknown upload/.test(cause.message) || /closed/.test(cause.message))) {
|
|
792
|
-
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
793
844
|
throw new ArtifactOperationError('verification_failed', { cause,
|
|
794
845
|
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
795
846
|
}
|
|
@@ -864,7 +915,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
864
915
|
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
865
916
|
const replay = await publication.replayFinalized(input);
|
|
866
917
|
if (replay !== undefined)
|
|
867
|
-
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
918
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
868
919
|
profile.validate(capability, args, request.idempotencyKey);
|
|
869
920
|
// Resolve the files/assets union BEFORE any commit step: one missing,
|
|
870
921
|
// expired or digest-mismatched asset fails the whole publish and commits nothing.
|
|
@@ -876,7 +927,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
876
927
|
...input, source: { kind: 'inline-original' },
|
|
877
928
|
profile: normalized.profile, files,
|
|
878
929
|
});
|
|
879
|
-
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
930
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
880
931
|
if (committed.ok) {
|
|
881
932
|
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
882
933
|
const entries = parsedBundleManifest.files ?? [];
|
|
@@ -914,7 +965,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
914
965
|
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
915
966
|
const replay = await publication.replayFinalized(input);
|
|
916
967
|
if (replay !== undefined)
|
|
917
|
-
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
968
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
918
969
|
profile.validate(capability, args, request.idempotencyKey);
|
|
919
970
|
const resolved = await resolveBundleAssets(invocation, artifactId, {
|
|
920
971
|
files: (normalized.files ?? []),
|
|
@@ -926,7 +977,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
926
977
|
...input, source: { kind: 'inline-original' },
|
|
927
978
|
profile: normalized.profile, files: resolved.files,
|
|
928
979
|
});
|
|
929
|
-
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
980
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
930
981
|
if (committed.ok) {
|
|
931
982
|
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
932
983
|
const entries = parsedBundleManifest.files ?? [];
|
|
@@ -974,14 +1025,25 @@ export function createHttpArtifactApp(deps) {
|
|
|
974
1025
|
limit: normalized.limit, cursor: normalized.cursor,
|
|
975
1026
|
state: id => deps.lifecycle.getReleaseState(id), urls: deps.publicationUrls });
|
|
976
1027
|
await visible(artifactId, invocation);
|
|
1028
|
+
if (deps.directory) {
|
|
1029
|
+
for (const version of body.versions) {
|
|
1030
|
+
if (typeof version.authorPrincipalId === 'string') {
|
|
1031
|
+
version.authorPrincipalId = (await deps.directory.describePrincipal(invocation.storageScopeId, version.authorPrincipalId))?.userRef ?? UNKNOWN_USER_REF;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
977
1035
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
978
1036
|
result: { status: 200, body } };
|
|
979
1037
|
}
|
|
980
1038
|
const releases = [];
|
|
981
1039
|
for (const release of await deps.publication.listReleases(artifactId)) {
|
|
982
1040
|
const manifest = parseManifest(release.manifest);
|
|
1041
|
+
const rawAuthor = typeof manifest.ownerId === 'string' ? manifest.ownerId : null;
|
|
1042
|
+
const author = rawAuthor === null || !deps.directory ? rawAuthor
|
|
1043
|
+
: (await deps.directory.describePrincipal(invocation.storageScopeId, rawAuthor))?.userRef
|
|
1044
|
+
?? UNKNOWN_USER_REF;
|
|
983
1045
|
releases.push({ releaseId: release.releaseId, createdAt: release.createdAt,
|
|
984
|
-
author
|
|
1046
|
+
author,
|
|
985
1047
|
state: await deps.lifecycle.getReleaseState(release.releaseId),
|
|
986
1048
|
isCurrent: current?.releaseId === release.releaseId,
|
|
987
1049
|
digest: release.manifestDigest });
|
|
@@ -1015,7 +1077,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
1015
1077
|
: acl.grants.filter((grant) => grant.principalId === invocation.actorId);
|
|
1016
1078
|
const grants = await Promise.all(visibleGrants.map(async (grant) => {
|
|
1017
1079
|
const person = await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId);
|
|
1018
|
-
const userRef = person?.userRef ??
|
|
1080
|
+
const userRef = person?.userRef ?? UNKNOWN_USER_REF;
|
|
1019
1081
|
const { effective, blockedBy } = evaluateGrant(acl, grant.principalId, deps.isApprovedAccount ?? (() => false));
|
|
1020
1082
|
return { userRef, displayName: person?.displayName ?? userRef,
|
|
1021
1083
|
...(person === undefined ? {} : { emailHint: maskEmailHint(person.email) }),
|
|
@@ -1025,7 +1087,8 @@ export function createHttpArtifactApp(deps) {
|
|
|
1025
1087
|
const owner = await deps.directory.describePrincipal(invocation.storageScopeId, acl.ownerId);
|
|
1026
1088
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
1027
1089
|
result: { status: 200, body: { artifactId, accessMode: accessModeOf(acl),
|
|
1028
|
-
owner: { userRef: owner?.userRef ??
|
|
1090
|
+
owner: { userRef: owner?.userRef ?? UNKNOWN_USER_REF,
|
|
1091
|
+
displayName: owner?.displayName ?? UNKNOWN_USER_REF },
|
|
1029
1092
|
canManage, grants } } };
|
|
1030
1093
|
}
|
|
1031
1094
|
const visibleArtifacts = [];
|
package/dist/mcp-core.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
|
10
10
|
export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
11
11
|
export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
|
|
12
12
|
export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
|
|
13
|
-
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.
|
|
13
|
+
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.16";
|
|
14
14
|
export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2"];
|
|
15
15
|
export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
|
|
16
16
|
export interface ArtifactsToolDefinition {
|
package/dist/mcp-core.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './profile/index.js';
|
|
|
6
6
|
export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
7
7
|
export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
|
|
8
8
|
export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
|
|
9
|
-
export const ARTIFACTS_PROVIDER_VERSION = '0.2.
|
|
9
|
+
export const ARTIFACTS_PROVIDER_VERSION = '0.2.16';
|
|
10
10
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { audienceOf, canManageAccess, PUBLIC_PRINCIPAL } from './access.js';
|
|
2
|
-
import { combineSharingPolicy, resolveSharingPolicy } from './ports.js';
|
|
2
|
+
import { combineSharingPolicy, resolveSharingPolicy, UNKNOWN_USER_REF } from './ports.js';
|
|
3
3
|
import { ArtifactOperationError } from './failures.js';
|
|
4
4
|
export function confirmationFailure(code, details) {
|
|
5
5
|
return new ArtifactOperationError('unauthorized_at_commit', { publicDetails: details,
|
|
@@ -67,10 +67,14 @@ export async function manageArtifact(deps, invocation, command, proof) {
|
|
|
67
67
|
return await deps.directory.resolvePrincipal(invocation.storageScopeId, principalId) ?? principalId;
|
|
68
68
|
};
|
|
69
69
|
// Unknown, inactive, unapproved and out-of-scope targets merge into the
|
|
70
|
-
// single `person_not_shareable` so no account status can be probed.
|
|
70
|
+
// single `person_not_shareable` so no account status can be probed. R5: the
|
|
71
|
+
// approval gate applies to `grant` only; `revoke` is the expected cleanup
|
|
72
|
+
// step for dormant (suspended or deleted) principals and must stay allowed.
|
|
71
73
|
const assertShareable = async (internal, action) => {
|
|
74
|
+
if (action !== 'grant')
|
|
75
|
+
return;
|
|
72
76
|
if (deps.directory === undefined) {
|
|
73
|
-
if (
|
|
77
|
+
if (!await deps.isApprovedPrincipal(internal))
|
|
74
78
|
throw refused('access_denied');
|
|
75
79
|
return;
|
|
76
80
|
}
|
|
@@ -78,14 +82,15 @@ export async function manageArtifact(deps, invocation, command, proof) {
|
|
|
78
82
|
throw shareableRefused();
|
|
79
83
|
};
|
|
80
84
|
// The receipt is model-visible: project internal principals to userRefs
|
|
81
|
-
// (audit events keep the internal form).
|
|
85
|
+
// (audit events keep the internal form). R1: a missing directory entry
|
|
86
|
+
// projects to the opaque unknown value, never the raw internal id.
|
|
82
87
|
const projectGrants = async (grants) => {
|
|
83
88
|
if (deps.directory === undefined)
|
|
84
89
|
return grants;
|
|
85
90
|
return Promise.all(grants.map(async (grant) => ({
|
|
86
91
|
...grant,
|
|
87
92
|
principalId: (await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId))?.userRef
|
|
88
|
-
??
|
|
93
|
+
?? UNKNOWN_USER_REF,
|
|
89
94
|
})));
|
|
90
95
|
};
|
|
91
96
|
const request = {
|
package/dist/server/ports.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ export interface PrincipalDirectoryPort {
|
|
|
49
49
|
/** Inverse projection: internal principal id → directory person (userRef/displayName/email). */
|
|
50
50
|
describePrincipal(scope: string, principalId: string): Promise<DirectoryPerson | undefined>;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* R1 typed unknown principal (review 1002): every model-visible projection of
|
|
54
|
+
* an internal principal whose directory entry is missing emits this opaque
|
|
55
|
+
* value instead of the raw internal id (`sub`). It never resolves back to a
|
|
56
|
+
* principal, so re-injecting it fails closed with `person_not_shareable`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const UNKNOWN_USER_REF = "unknown";
|
|
52
59
|
/**
|
|
53
60
|
* Mask an email for model payloads: first local-part character kept, rest of
|
|
54
61
|
* the local part masked, domain visible — lifts homonyms without disclosing
|
package/dist/server/ports.js
CHANGED
|
@@ -21,6 +21,13 @@ export function createCryptoUuid() {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* R1 typed unknown principal (review 1002): every model-visible projection of
|
|
26
|
+
* an internal principal whose directory entry is missing emits this opaque
|
|
27
|
+
* value instead of the raw internal id (`sub`). It never resolves back to a
|
|
28
|
+
* principal, so re-injecting it fails closed with `person_not_shareable`.
|
|
29
|
+
*/
|
|
30
|
+
export const UNKNOWN_USER_REF = 'unknown';
|
|
24
31
|
/**
|
|
25
32
|
* Mask an email for model payloads: first local-part character kept, rest of
|
|
26
33
|
* the local part masked, domain visible — lifts homonyms without disclosing
|
package/dist/server/templates.js
CHANGED
|
@@ -64,17 +64,18 @@ const GUIDE_V1 = [
|
|
|
64
64
|
' commitState, replayed/output on success, or typed error details on failure.',
|
|
65
65
|
'- `artifacts_create_upload`: mint a presigned PUT for one staging key',
|
|
66
66
|
' (`artifacts/<scope>/staging/<uploadId>`, URL expiry <= 10 minutes). The',
|
|
67
|
-
' signature binds the content type and the exact declared content length
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
67
|
+
' signature binds the content type and the exact declared content length,',
|
|
68
|
+
' and nothing else: send exactly the returned `requiredHeaders`, no extra',
|
|
69
|
+
' header (strict S3 implementations refuse unsigned `x-amz-*` headers).',
|
|
70
|
+
' Perform the PUT yourself (curl, SDK, CI) — no MCP call ever carries file',
|
|
71
|
+
' bytes. Open sessions per principal are quota-limited.',
|
|
72
72
|
'- `artifacts_commit_upload`: declare `{path, mimeType, digest, size}` for a',
|
|
73
73
|
' staged upload; the server re-reads the staged object once and re-verifies',
|
|
74
74
|
' size, SHA-256 digest and MIME (magic bytes / strict UTF-8 / SVG rules)',
|
|
75
75
|
' before promoting it to the digest-addressed blob store and pinning it.',
|
|
76
|
-
' A wrong size or digest is refused with `verification_failed
|
|
77
|
-
' is
|
|
76
|
+
' A wrong size or digest is refused with `verification_failed`: the staged',
|
|
77
|
+
' object is deleted, the session is closed, and nothing is pinned.',
|
|
78
|
+
' Commit creates no release by itself.',
|
|
78
79
|
'- `artifacts_publish_bundle`: one atomic release from inline `files` and/or',
|
|
79
80
|
' `assets` — each asset is `{path, uploadId}` (staged via create_upload +',
|
|
80
81
|
' PUT + commit_upload) or `{path, digest, size, mimeType}` (an already-pinned',
|
|
@@ -122,8 +123,8 @@ const GUIDE_V1 = [
|
|
|
122
123
|
'1. `artifacts_ensure` to resolve the artifact.',
|
|
123
124
|
'2. Per file: `artifacts_create_upload {artifactId, mimeType, maxSize?}`,',
|
|
124
125
|
' then PUT the local file to the returned `uploadUrl` with exactly the',
|
|
125
|
-
' returned `requiredHeaders`
|
|
126
|
-
'
|
|
126
|
+
' returned `requiredHeaders` and no other header, then',
|
|
127
|
+
' `artifacts_commit_upload {artifactId, uploadId, path,',
|
|
127
128
|
' mimeType, digest: "sha256:<hex>", size, idempotencyKey}`.',
|
|
128
129
|
'3. One `artifacts_publish_bundle {artifactId, idempotencyKey,',
|
|
129
130
|
' expectedCurrentReleaseId, assets: [{path, uploadId}, ...]}` — assets-only',
|
|
@@ -137,7 +137,6 @@ export interface UploadPageService {
|
|
|
137
137
|
expiresAt: string;
|
|
138
138
|
maxSize: number;
|
|
139
139
|
requiredHeaders: Record<string, string>;
|
|
140
|
-
checksumHeader: 'x-amz-checksum-sha256';
|
|
141
140
|
stagingKey: string;
|
|
142
141
|
}>;
|
|
143
142
|
commitFile(input: PageCommitInput): Promise<StagedFileRecord>;
|
|
@@ -188,7 +188,6 @@ const chunked = (bytes, f) => {
|
|
|
188
188
|
for (let i = 0; i < view.length; i += 0x8000) out += f(view.subarray(i, i + 0x8000)));
|
|
189
189
|
return out;
|
|
190
190
|
};
|
|
191
|
-
const b64 = (bytes) => btoa(chunked(bytes, (part) => String.fromCharCode(...part)));
|
|
192
191
|
const hex = (bytes) => chunked(bytes, (part) => [...part].map((b) => b.toString(16).padStart(2, '0')).join(''));
|
|
193
192
|
const row = (path) => {
|
|
194
193
|
const li = document.createElement('li');
|
|
@@ -204,8 +203,7 @@ async function stage(file, relPath) {
|
|
|
204
203
|
setStatus('uploading');
|
|
205
204
|
const buffer = await file.arrayBuffer();
|
|
206
205
|
const put = async (upload) => fetch(upload.uploadUrl, { method: 'PUT', body: file,
|
|
207
|
-
headers: { 'content-type': upload.requiredHeaders['content-type']
|
|
208
|
-
'x-amz-checksum-sha256': b64(await crypto.subtle.digest('SHA-256', buffer)) } });
|
|
206
|
+
headers: { 'content-type': upload.requiredHeaders['content-type'] } });
|
|
209
207
|
let upload = created;
|
|
210
208
|
let response = await put(upload);
|
|
211
209
|
if (!response.ok) {
|
package/dist/server/uploads.d.ts
CHANGED
|
@@ -79,17 +79,18 @@ export interface StagingStore {
|
|
|
79
79
|
}[]>;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Presigner port. The signature binds content-type
|
|
83
|
-
* (declared size)
|
|
84
|
-
*
|
|
82
|
+
* Presigner port. The signature binds content-type and the EXACT
|
|
83
|
+
* content-length (declared size); no content-length range exists in a SigV4
|
|
84
|
+
* presigned PUT (review finding 3). No checksum header is signed: the digest
|
|
85
|
+
* is declared at commit, and announcing an unsigned `x-amz-*` header makes
|
|
86
|
+
* strict S3 implementations refuse the PUT. The returned headers are the
|
|
87
|
+
* whole contract: the client sends exactly these headers, nothing more.
|
|
85
88
|
*/
|
|
86
89
|
export interface UploadSignerPort {
|
|
87
90
|
signPut(input: {
|
|
88
91
|
key: string;
|
|
89
92
|
contentType: string;
|
|
90
93
|
contentLength: number;
|
|
91
|
-
/** Canonical `sha256:<hex>` digest, when known at signing time. */
|
|
92
|
-
checksumSha256?: string;
|
|
93
94
|
expiresInSeconds: number;
|
|
94
95
|
}): Promise<{
|
|
95
96
|
url: string;
|
|
@@ -99,16 +100,21 @@ export interface UploadSignerPort {
|
|
|
99
100
|
expiresAt: string;
|
|
100
101
|
}>;
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Typed verification failure for the upload channel (fail-closed commit).
|
|
105
|
+
* Hosts map this to `verification_failed` without trusting the message text.
|
|
106
|
+
*/
|
|
107
|
+
export type UploadVerificationReason = 'unknown_upload' | 'session_not_open' | 'session_expired' | 'staged_missing' | 'size_mismatch' | 'digest_mismatch' | 'mime_mismatch' | 'cas_readback_mismatch';
|
|
108
|
+
export declare class UploadVerificationError extends Error {
|
|
109
|
+
readonly reason: UploadVerificationReason;
|
|
110
|
+
readonly uploadId: string;
|
|
111
|
+
constructor(reason: UploadVerificationReason, uploadId: string, message: string);
|
|
112
|
+
}
|
|
102
113
|
export declare const STAGING_KEY_PATTERN: RegExp;
|
|
103
114
|
/** Staging key of one upload session. */
|
|
104
115
|
export declare function stagingKey(storageScopeId: string, uploadId: string): string;
|
|
105
116
|
/** Staging prefix of one scope (LOT 2 §D.1 orphan pass enumerates it). */
|
|
106
117
|
export declare function stagingPrefix(storageScopeId: string): string;
|
|
107
|
-
/**
|
|
108
|
-
* Value of the `x-amz-checksum-sha256` header for a canonical `sha256:<hex>`
|
|
109
|
-
* digest: S3 expects the base64 of the raw digest bytes (no `sha256:` prefix).
|
|
110
|
-
*/
|
|
111
|
-
export declare function checksumHeaderValue(digest: string): string;
|
|
112
118
|
/** Reject anything but a staging key, before any I/O. */
|
|
113
119
|
export declare function assertStagingKey(key: string): void;
|
|
114
120
|
/** Reject empty or escaping staging prefixes before enumeration. */
|
|
@@ -128,16 +134,19 @@ export declare function createMemoryUploadSigner(): {
|
|
|
128
134
|
key: string;
|
|
129
135
|
contentType: string;
|
|
130
136
|
contentLength: number;
|
|
131
|
-
checksumSha256?: string | undefined;
|
|
132
137
|
expiresAt: string;
|
|
133
138
|
url: string;
|
|
134
139
|
}[];
|
|
135
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Simulate the client PUT against a strict "S3": the signed headers are
|
|
142
|
+
* enforced exactly, and any `x-amz-*` header outside the signed set is
|
|
143
|
+
* refused — mirroring OVH S3, which rejects a presigned PUT carrying an
|
|
144
|
+
* unsigned `x-amz-checksum-sha256` with 403 AccessDenied.
|
|
145
|
+
*/
|
|
136
146
|
put(signedPut: {
|
|
137
147
|
key: string;
|
|
138
148
|
contentType: string;
|
|
139
149
|
contentLength: number;
|
|
140
|
-
checksumSha256?: string;
|
|
141
150
|
}, bytes: Uint8Array, headers: Record<string, string>): void;
|
|
142
151
|
};
|
|
143
152
|
export interface CreateUploadInput {
|
|
@@ -163,14 +172,13 @@ export interface CreateUploadResult {
|
|
|
163
172
|
/** Presigned-URL expiry (≤ 10 minutes). */
|
|
164
173
|
expiresAt: string;
|
|
165
174
|
maxSize: number;
|
|
166
|
-
/** Headers the client must send with exactly these values (bound by the signature). */
|
|
167
|
-
requiredHeaders: Record<string, string>;
|
|
168
175
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
176
|
+
* Exactly the signed header set (`content-type` + `content-length`): the
|
|
177
|
+
* client sends these headers with exactly these values and nothing else.
|
|
178
|
+
* No `x-amz-*` header is announced, because no `x-amz-*` header is signed
|
|
179
|
+
* and strict S3 implementations refuse unsigned ones.
|
|
172
180
|
*/
|
|
173
|
-
|
|
181
|
+
requiredHeaders: Record<string, string>;
|
|
174
182
|
stagingKey: string;
|
|
175
183
|
}
|
|
176
184
|
export interface CommitUploadInput {
|
package/dist/server/uploads.js
CHANGED
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
* `commit_upload` re-reads the staged object once and verifies the declared
|
|
9
9
|
* size and SHA-256 digest before anything is pinned.
|
|
10
10
|
*
|
|
11
|
-
* SigV4 note (review finding 3): a presigned PUT cannot
|
|
12
|
-
* content-length RANGE (that exists only in POST policies), so the
|
|
13
|
-
* binds an EXACT Content-Length (the declared size) plus
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
11
|
+
* SigV4 note (review finding 3, hardened 0.2.16): a presigned PUT cannot
|
|
12
|
+
* carry a content-length RANGE (that exists only in POST policies), so the
|
|
13
|
+
* signature binds an EXACT Content-Length (the declared size) plus
|
|
14
|
+
* content-type — and nothing else. The digest is declared at commit, so no
|
|
15
|
+
* checksum header can be signed at create time; announcing one anyway makes
|
|
16
|
+
* strict S3 implementations (OVH) refuse the PUT with 403 because the header
|
|
17
|
+
* is present but not signed. The client therefore sends exactly the announced
|
|
18
|
+
* headers, and commit re-reads the staged object once and re-verifies size,
|
|
19
|
+
* SHA-256 digest and MIME server-side before pinning (fail-closed: any
|
|
20
|
+
* mismatch refuses with a typed error, deletes the staged object, closes the
|
|
21
|
+
* session, and creates no release). Residual exposure of a leaked URL is
|
|
22
|
+
* bounded by the declared size (≤ 16 MiB), the per-principal open-session
|
|
23
|
+
* quota and the enforced sweeper (gc.ts).
|
|
22
24
|
*
|
|
23
25
|
* Sessions are durable rows (migration 0007 ALTERs `artifacts.uploads`);
|
|
24
26
|
* the byte store, session store and signer are injected ports — the memory
|
|
@@ -36,6 +38,16 @@ export const STAGED_FILE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
36
38
|
export const STAGED_FILE_TTL_MAX_MS = 7 * 24 * 60 * 60 * 1000;
|
|
37
39
|
export const ORPHAN_STAGING_GRACE_MS = 60 * 60 * 1000;
|
|
38
40
|
export const ORPHAN_SWEEP_MAX_KEYS = 500;
|
|
41
|
+
export class UploadVerificationError extends Error {
|
|
42
|
+
reason;
|
|
43
|
+
uploadId;
|
|
44
|
+
constructor(reason, uploadId, message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'UploadVerificationError';
|
|
47
|
+
this.reason = reason;
|
|
48
|
+
this.uploadId = uploadId;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
39
51
|
export const STAGING_KEY_PATTERN = /^artifacts\/[A-Za-z0-9_-]+\/staging\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
40
52
|
/** Staging key of one upload session. */
|
|
41
53
|
export function stagingKey(storageScopeId, uploadId) {
|
|
@@ -45,16 +57,6 @@ export function stagingKey(storageScopeId, uploadId) {
|
|
|
45
57
|
export function stagingPrefix(storageScopeId) {
|
|
46
58
|
return `artifacts/${storageScopeId}/staging/`;
|
|
47
59
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Value of the `x-amz-checksum-sha256` header for a canonical `sha256:<hex>`
|
|
50
|
-
* digest: S3 expects the base64 of the raw digest bytes (no `sha256:` prefix).
|
|
51
|
-
*/
|
|
52
|
-
export function checksumHeaderValue(digest) {
|
|
53
|
-
const match = /^sha256:([0-9a-f]{64})$/.exec(digest);
|
|
54
|
-
if (match === null)
|
|
55
|
-
throw new Error(`invalid sha256 digest: ${digest}`);
|
|
56
|
-
return Buffer.from(match[1], 'hex').toString('base64');
|
|
57
|
-
}
|
|
58
60
|
/** Reject anything but a staging key, before any I/O. */
|
|
59
61
|
export function assertStagingKey(key) {
|
|
60
62
|
if (!STAGING_KEY_PATTERN.test(key)) {
|
|
@@ -200,9 +202,7 @@ export function createMemoryUploadSigner() {
|
|
|
200
202
|
}
|
|
201
203
|
const expiresAt = new Date(Date.now() + input.expiresInSeconds * 1000).toISOString();
|
|
202
204
|
const url = `https://s3.test/${input.key}?X-Amz-Signature=mem-${signed.length}`;
|
|
203
|
-
const checksumHeader = input.checksumSha256 === undefined ? undefined : checksumHeaderValue(input.checksumSha256);
|
|
204
205
|
signed.push({ key: input.key, contentType: input.contentType, contentLength: input.contentLength,
|
|
205
|
-
...(checksumHeader === undefined ? {} : { checksumSha256: checksumHeader }),
|
|
206
206
|
expiresAt, url });
|
|
207
207
|
return Promise.resolve({
|
|
208
208
|
url,
|
|
@@ -210,7 +210,6 @@ export function createMemoryUploadSigner() {
|
|
|
210
210
|
headers: {
|
|
211
211
|
'content-type': input.contentType,
|
|
212
212
|
'content-length': String(input.contentLength),
|
|
213
|
-
...(checksumHeader === undefined ? {} : { 'x-amz-checksum-sha256': checksumHeader }),
|
|
214
213
|
},
|
|
215
214
|
expiresAt,
|
|
216
215
|
});
|
|
@@ -219,7 +218,12 @@ export function createMemoryUploadSigner() {
|
|
|
219
218
|
return {
|
|
220
219
|
signer,
|
|
221
220
|
signed,
|
|
222
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* Simulate the client PUT against a strict "S3": the signed headers are
|
|
223
|
+
* enforced exactly, and any `x-amz-*` header outside the signed set is
|
|
224
|
+
* refused — mirroring OVH S3, which rejects a presigned PUT carrying an
|
|
225
|
+
* unsigned `x-amz-checksum-sha256` with 403 AccessDenied.
|
|
226
|
+
*/
|
|
223
227
|
put(signedPut, bytes, headers) {
|
|
224
228
|
if (String(bytes.length) !== headers['content-length'] || bytes.length !== signedPut.contentLength) {
|
|
225
229
|
throw new Error(`content-length mismatch: signed ${signedPut.contentLength}, body ${bytes.length}`);
|
|
@@ -227,12 +231,10 @@ export function createMemoryUploadSigner() {
|
|
|
227
231
|
if (headers['content-type'] !== signedPut.contentType) {
|
|
228
232
|
throw new Error('content-type mismatch with the signed header');
|
|
229
233
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
createHash('sha256').update(bytes).digest('base64') !== headers['x-amz-checksum-sha256']) {
|
|
235
|
-
throw new Error('BadDigest: body does not match x-amz-checksum-sha256');
|
|
234
|
+
for (const key of Object.keys(headers)) {
|
|
235
|
+
if (key.startsWith('x-amz-')) {
|
|
236
|
+
throw new Error(`x-amz header present but not signed: ${key}`);
|
|
237
|
+
}
|
|
236
238
|
}
|
|
237
239
|
},
|
|
238
240
|
};
|
|
@@ -315,14 +317,14 @@ export function createUploadService(deps, options) {
|
|
|
315
317
|
emit({ name: 'upload_sessions_created' });
|
|
316
318
|
// The signature binds content-type and the EXACT declared Content-Length
|
|
317
319
|
// (a presigned PUT cannot carry a content-length range). The digest is
|
|
318
|
-
// declared at commit, so
|
|
319
|
-
//
|
|
320
|
+
// declared at commit, so no checksum header is signed or announced;
|
|
321
|
+
// commit re-verifies size, digest and MIME server-side, fail-closed.
|
|
320
322
|
const signed = await deps.signer.signPut({
|
|
321
323
|
key, contentType: input.mimeType, contentLength: maxSize, expiresInSeconds: UPLOAD_URL_TTL_SECONDS,
|
|
322
324
|
});
|
|
323
325
|
return {
|
|
324
326
|
uploadId, uploadUrl: signed.url, method: signed.method, expiresAt: signed.expiresAt, maxSize,
|
|
325
|
-
requiredHeaders: signed.headers,
|
|
327
|
+
requiredHeaders: signed.headers,
|
|
326
328
|
stagingKey: key,
|
|
327
329
|
};
|
|
328
330
|
});
|
|
@@ -331,28 +333,34 @@ export function createUploadService(deps, options) {
|
|
|
331
333
|
return deps.sessions.get(input.uploadId).then((session) => {
|
|
332
334
|
if (session === undefined || session.artifactId !== input.artifactId ||
|
|
333
335
|
session.storageScopeId !== input.storageScopeId || session.ownerId !== input.ownerId) {
|
|
334
|
-
throw new
|
|
336
|
+
throw new UploadVerificationError('unknown_upload', input.uploadId, `unknown upload for this artifact/owner/scope: ${input.uploadId}`);
|
|
337
|
+
}
|
|
338
|
+
if (session.state !== 'open') {
|
|
339
|
+
throw new UploadVerificationError('session_not_open', input.uploadId, `upload not open (${session.state}): ${input.uploadId}`);
|
|
335
340
|
}
|
|
336
|
-
if (session.state !== 'open')
|
|
337
|
-
throw new Error(`upload not open (${session.state}): ${input.uploadId}`);
|
|
338
341
|
if (new Date(session.expiresAt).getTime() <= now().getTime()) {
|
|
339
|
-
throw new
|
|
342
|
+
throw new UploadVerificationError('session_expired', input.uploadId, `upload session expired: ${input.uploadId}`);
|
|
340
343
|
}
|
|
341
344
|
return session;
|
|
342
345
|
});
|
|
343
346
|
},
|
|
344
347
|
verifyStaged(session, bytes, expected) {
|
|
345
348
|
if (bytes.length !== expected.size) {
|
|
346
|
-
throw new
|
|
349
|
+
throw new UploadVerificationError('size_mismatch', session.uploadId, `upload size mismatch for ${session.uploadId}: staged ${bytes.length}, declared ${expected.size}`);
|
|
347
350
|
}
|
|
348
351
|
const actual = `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
349
352
|
if (actual !== expected.digest) {
|
|
350
|
-
throw new
|
|
353
|
+
throw new UploadVerificationError('digest_mismatch', session.uploadId, `upload digest mismatch for ${session.uploadId}: staged ${actual}`);
|
|
351
354
|
}
|
|
352
355
|
if (expected.mimeType !== session.mimeType) {
|
|
353
|
-
throw new
|
|
356
|
+
throw new UploadVerificationError('mime_mismatch', session.uploadId, `upload MIME mismatch for ${session.uploadId}: session ${session.mimeType}, declared ${expected.mimeType}`);
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
validateFileBytes(expected.mimeType, bytes);
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
throw new UploadVerificationError('mime_mismatch', session.uploadId, `upload content mismatch for ${session.uploadId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
354
363
|
}
|
|
355
|
-
validateFileBytes(expected.mimeType, bytes);
|
|
356
364
|
},
|
|
357
365
|
async completeCommit(session, record) {
|
|
358
366
|
const staged = {
|
|
@@ -373,20 +381,43 @@ export async function commitStagedUpload(service, deps, input, channel = 'agent'
|
|
|
373
381
|
labels: { channel, ...(event.labels ?? {}) } });
|
|
374
382
|
};
|
|
375
383
|
const fail = (error) => {
|
|
376
|
-
if (
|
|
384
|
+
if (error instanceof UploadVerificationError ||
|
|
385
|
+
!(error instanceof Error) || !/budget exceeded/.test(error.message)) {
|
|
377
386
|
emit({ name: 'upload_commits', labels: { result: 'verification_failed' } });
|
|
378
387
|
}
|
|
379
388
|
throw error;
|
|
380
389
|
};
|
|
390
|
+
// Fail-closed cleanup: a verification failure deletes the staged object and
|
|
391
|
+
// closes the session, so a poisoned upload can never be retried into a
|
|
392
|
+
// release and no declaration oracle survives. Best-effort: the refusal is
|
|
393
|
+
// what matters; cleanup failures never mask it.
|
|
394
|
+
const quarantine = async (uploadId, stagingKeyToDelete) => {
|
|
395
|
+
if (stagingKeyToDelete !== undefined) {
|
|
396
|
+
await deps.staging.delete(stagingKeyToDelete).catch(() => undefined);
|
|
397
|
+
}
|
|
398
|
+
await deps.sessions.markExpired(uploadId).catch(() => undefined);
|
|
399
|
+
};
|
|
381
400
|
const session = await service.sessionForCommit(input).catch((error) => fail(error));
|
|
382
401
|
const key = stagingKey(input.storageScopeId, input.uploadId);
|
|
383
|
-
const bytes = await deps.staging.get(key)
|
|
384
|
-
|
|
402
|
+
const bytes = await deps.staging.get(key);
|
|
403
|
+
if (bytes === undefined) {
|
|
404
|
+
const error = new UploadVerificationError('staged_missing', input.uploadId, `staged object missing for ${input.uploadId}`);
|
|
405
|
+
emit({ name: 'upload_commits', labels: { result: 'verification_failed' } });
|
|
406
|
+
await quarantine(input.uploadId, undefined);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
385
409
|
try {
|
|
386
410
|
service.verifyStaged(session, bytes, { digest: input.digest, size: input.size, mimeType: input.mimeType });
|
|
387
411
|
}
|
|
388
412
|
catch (error) {
|
|
389
|
-
|
|
413
|
+
if (error instanceof UploadVerificationError) {
|
|
414
|
+
emit({ name: 'upload_commits', labels: { result: 'verification_failed' } });
|
|
415
|
+
await quarantine(input.uploadId, key);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
fail(error);
|
|
419
|
+
}
|
|
420
|
+
throw error;
|
|
390
421
|
}
|
|
391
422
|
// LOT 2 §D.2: per-artifact staged caps, checked at commit for both channels.
|
|
392
423
|
const existing = await deps.sessions.listStagedFiles(input.artifactId);
|
|
@@ -401,7 +432,11 @@ export async function commitStagedUpload(service, deps, input, channel = 'agent'
|
|
|
401
432
|
const readBack = await deps.blobs.getBlob(casKey);
|
|
402
433
|
if (readBack === undefined || readBack.byteLength !== input.size ||
|
|
403
434
|
`sha256:${createHash('sha256').update(readBack).digest('hex')}` !== input.digest) {
|
|
404
|
-
|
|
435
|
+
const error = new UploadVerificationError('cas_readback_mismatch', input.uploadId, `CAS read-back mismatch for ${input.uploadId}`);
|
|
436
|
+
emit({ name: 'upload_commits', labels: { result: 'verification_failed' } });
|
|
437
|
+
await deps.blobs.deleteBlob(casKey).catch(() => undefined);
|
|
438
|
+
await quarantine(input.uploadId, key);
|
|
439
|
+
throw error;
|
|
405
440
|
}
|
|
406
441
|
const pinReason = `upload:${input.uploadId}`;
|
|
407
442
|
await deps.refs.pin(input.digest, pinReason);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"description": "Generic configurable artifacts MCP and artifact service: StorageScope/Artifact/Binding/Release model, canonical manifests, object authorization, idempotent intents (spec-v8 §9).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|