@sentropic/artifacts 0.2.15 → 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 +28 -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 +17 -3
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- 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,33 @@
|
|
|
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
|
+
|
|
3
31
|
## 0.2.15
|
|
4
32
|
|
|
5
33
|
- R1: every model-visible userRef projection emits the opaque `unknown` value
|
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
|
@@ -9,7 +9,7 @@ import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy, UNKNOWN_USER
|
|
|
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';
|
|
@@ -796,7 +796,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
796
796
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
797
797
|
result: { status: 201, body: { uploadId: created.uploadId, uploadUrl: created.uploadUrl,
|
|
798
798
|
method: created.method, expiresAt: created.expiresAt, maxSize: created.maxSize,
|
|
799
|
-
requiredHeaders: created.requiredHeaders
|
|
799
|
+
requiredHeaders: created.requiredHeaders } } };
|
|
800
800
|
}
|
|
801
801
|
if (capability === 'artifacts_commit_upload') {
|
|
802
802
|
const artifactId = normalized.artifactId;
|
|
@@ -825,8 +825,22 @@ export function createHttpArtifactApp(deps) {
|
|
|
825
825
|
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
826
826
|
publicDetails: { upload: { reason: 'staged_budget' } } });
|
|
827
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.
|
|
828
843
|
if (cause instanceof Error && (/unknown upload/.test(cause.message) || /closed/.test(cause.message))) {
|
|
829
|
-
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
830
844
|
throw new ArtifactOperationError('verification_failed', { cause,
|
|
831
845
|
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
832
846
|
}
|
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).
|
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",
|