@sentropic/artifacts 0.2.12 → 0.2.14
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 +93 -0
- package/README.md +45 -10
- package/dist/adapters/local-blob.d.ts +3 -0
- package/dist/adapters/local-blob.js +93 -0
- package/dist/adapters/postgres-management.js +3 -2
- package/dist/adapters/postgres-reader-consent.d.ts +11 -0
- package/dist/adapters/postgres-reader-consent.js +109 -0
- package/dist/adapters/postgres-uploads.d.ts +14 -0
- package/dist/adapters/postgres-uploads.js +174 -0
- package/dist/adapters/postgres.js +4 -3
- package/dist/adapters/s3-uploads.d.ts +33 -0
- package/dist/adapters/s3-uploads.js +105 -0
- package/dist/adapters/s3.js +23 -0
- package/dist/adapters/sqlite-activation.d.ts +20 -0
- package/dist/adapters/sqlite-activation.js +205 -0
- package/dist/adapters/sqlite-commit.d.ts +15 -0
- package/dist/adapters/sqlite-commit.js +89 -0
- package/dist/adapters/sqlite-management.d.ts +10 -0
- package/dist/adapters/sqlite-management.js +60 -0
- package/dist/adapters/sqlite-sql.d.ts +32 -0
- package/dist/adapters/sqlite-sql.js +36 -0
- package/dist/adapters/sqlite-store.d.ts +12 -0
- package/dist/adapters/sqlite-store.js +410 -0
- package/dist/adapters/sqlite.d.ts +33 -0
- package/dist/adapters/sqlite.js +95 -0
- package/dist/content/handler.d.ts +5 -0
- package/dist/content/handler.js +80 -9
- package/dist/content/headers.js +12 -0
- package/dist/http.d.ts +32 -2
- package/dist/http.js +615 -13
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +90 -4
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +7 -0
- package/dist/profile/index.js +43 -2
- package/dist/profile/radar.js +7 -0
- package/dist/profile/schemas.js +119 -0
- package/dist/profile/validation.d.ts +11 -0
- package/dist/profile/validation.js +98 -6
- package/dist/server/access.d.ts +2 -0
- package/dist/server/command-identity.d.ts +1 -1
- package/dist/server/command-identity.js +6 -3
- package/dist/server/consent.d.ts +65 -0
- package/dist/server/consent.js +42 -0
- package/dist/server/gc.d.ts +42 -0
- package/dist/server/gc.js +98 -0
- package/dist/server/management.d.ts +3 -1
- package/dist/server/management.js +48 -7
- package/dist/server/metrics.d.ts +21 -0
- package/dist/server/metrics.js +6 -0
- package/dist/server/mime.d.ts +26 -2
- package/dist/server/mime.js +124 -2
- package/dist/server/ports.d.ts +29 -0
- package/dist/server/ports.js +11 -0
- package/dist/server/publication-limits.d.ts +20 -0
- package/dist/server/publication-limits.js +27 -1
- package/dist/server/publication.d.ts +14 -0
- package/dist/server/publication.js +10 -2
- package/dist/server/reader-store.d.ts +58 -0
- package/dist/server/reader-store.js +109 -0
- package/dist/server/source-read.d.ts +12 -9
- package/dist/server/source-read.js +17 -5
- package/dist/server/templates.js +50 -2
- package/dist/server/upload-page.d.ts +157 -0
- package/dist/server/upload-page.js +438 -0
- package/dist/server/uploads.d.ts +229 -19
- package/dist/server/uploads.js +387 -80
- package/migrations/0007_uploads.sql +43 -0
- package/migrations/0008_reader_consent.sql +48 -0
- package/migrations/0009_upload_pages.sql +25 -0
- package/package.json +34 -1
- package/sql/reader-consent.sql +47 -0
- package/sql/sqlite/0001_artifacts.sql +156 -0
- package/sql/sqlite/0002_activation.sql +73 -0
package/dist/content/handler.js
CHANGED
|
@@ -42,7 +42,48 @@ export function createContentHandler(deps) {
|
|
|
42
42
|
const approved = (await deps.isApprovedAccount?.(subjectId)) ?? false;
|
|
43
43
|
return deps.lifecycle.canRead({ artifactId, state }, acl, subjectId, 'read', () => approved, policy);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Files parity LOT 2 §B.4: RFC 9110 §14 single-range subset. Only the
|
|
47
|
+
* `bytes=` unit with one satisfiable range is honored; malformed or
|
|
48
|
+
* multi-range headers fall back to the whole file (never an error).
|
|
49
|
+
*/
|
|
50
|
+
function parseRange(header, size) {
|
|
51
|
+
if (header === undefined)
|
|
52
|
+
return 'full';
|
|
53
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
54
|
+
if (match?.[1] === undefined || match[2] === undefined)
|
|
55
|
+
return 'ignore';
|
|
56
|
+
if (match[1] === '' && match[2] === '')
|
|
57
|
+
return 'ignore';
|
|
58
|
+
if (match[1] === '') {
|
|
59
|
+
// Suffix range: the last N bytes; longer than the file ⇒ the file.
|
|
60
|
+
const suffix = Number(match[2]);
|
|
61
|
+
if (!Number.isSafeInteger(suffix) || suffix <= 0)
|
|
62
|
+
return 'unsatisfiable';
|
|
63
|
+
if (suffix >= size)
|
|
64
|
+
return size === 0 ? 'unsatisfiable' : { start: 0, end: size - 1 };
|
|
65
|
+
return { start: size - suffix, end: size - 1 };
|
|
66
|
+
}
|
|
67
|
+
const start = Number(match[1]);
|
|
68
|
+
if (!Number.isSafeInteger(start) || start >= size)
|
|
69
|
+
return 'unsatisfiable';
|
|
70
|
+
if (match[2] === '')
|
|
71
|
+
return { start, end: size - 1 };
|
|
72
|
+
const end = Number(match[2]);
|
|
73
|
+
if (!Number.isSafeInteger(end) || end < start)
|
|
74
|
+
return 'ignore';
|
|
75
|
+
return { start, end: Math.min(end, size - 1) };
|
|
76
|
+
}
|
|
77
|
+
async function rangeSlice(key, start, end) {
|
|
78
|
+
const ranged = await deps.blobs.getBlobRange?.(key, start, end);
|
|
79
|
+
if (ranged !== undefined) {
|
|
80
|
+
// A short store read is distrusted: serve the whole file instead.
|
|
81
|
+
return ranged.length === end - start + 1 ? ranged : undefined;
|
|
82
|
+
}
|
|
83
|
+
const bytes = await deps.blobs.getBlob(key);
|
|
84
|
+
return bytes === undefined ? undefined : bytes.slice(start, end + 1);
|
|
85
|
+
}
|
|
86
|
+
async function serveFile(artifactId, manifest, filePath, rangeHeader) {
|
|
46
87
|
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
47
88
|
if (acl === undefined)
|
|
48
89
|
return fail(404);
|
|
@@ -53,18 +94,48 @@ export function createContentHandler(deps) {
|
|
|
53
94
|
if (file === undefined || typeof file.digest !== 'string')
|
|
54
95
|
return fail(404);
|
|
55
96
|
const hex = file.digest.startsWith('sha256:') ? file.digest.slice(7) : file.digest;
|
|
56
|
-
const
|
|
97
|
+
const key = `artifacts/${acl.storageScopeId}/blobs/sha256/${hex}`;
|
|
98
|
+
const mimeType = typeof file.mimeType === 'string' ? file.mimeType : 'application/octet-stream';
|
|
99
|
+
const size = typeof file.size === 'number' ? file.size : undefined;
|
|
100
|
+
const emitRange = (result) => {
|
|
101
|
+
if (deps.metrics !== undefined && rangeHeader !== undefined) {
|
|
102
|
+
deps.metrics.emit({ name: 'content_range_requests', labels: { result } });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if (rangeHeader !== undefined && size !== undefined) {
|
|
106
|
+
const range = parseRange(rangeHeader, size);
|
|
107
|
+
if (range === 'unsatisfiable') {
|
|
108
|
+
emitRange('416');
|
|
109
|
+
const response = fail(416);
|
|
110
|
+
return { ...response, headers: { ...response.headers, 'content-range': `bytes */${size}` } };
|
|
111
|
+
}
|
|
112
|
+
if (range !== 'full' && range !== 'ignore') {
|
|
113
|
+
const bytes = await rangeSlice(key, range.start, range.end);
|
|
114
|
+
if (bytes === undefined)
|
|
115
|
+
return fail(404);
|
|
116
|
+
emitRange('206');
|
|
117
|
+
return {
|
|
118
|
+
status: 206,
|
|
119
|
+
headers: { ...contentHeaders({ mimeType, size: bytes.length,
|
|
120
|
+
assetCacheSeconds: deps.assetCacheSeconds }),
|
|
121
|
+
'content-range': `bytes ${range.start}-${range.end}/${size}`,
|
|
122
|
+
'accept-ranges': 'bytes' },
|
|
123
|
+
bytes,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (range === 'ignore')
|
|
127
|
+
emitRange('ignored');
|
|
128
|
+
}
|
|
129
|
+
const bytes = await deps.blobs.getBlob(key);
|
|
57
130
|
if (bytes === undefined)
|
|
58
131
|
return fail(404);
|
|
59
|
-
if (
|
|
132
|
+
if (size !== undefined && bytes.length !== size)
|
|
60
133
|
return fail(422);
|
|
61
134
|
return {
|
|
62
135
|
status: 200,
|
|
63
|
-
headers: contentHeaders({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
assetCacheSeconds: deps.assetCacheSeconds,
|
|
67
|
-
}),
|
|
136
|
+
headers: { ...contentHeaders({ mimeType, size: bytes.length,
|
|
137
|
+
assetCacheSeconds: deps.assetCacheSeconds }),
|
|
138
|
+
'accept-ranges': 'bytes' },
|
|
68
139
|
bytes,
|
|
69
140
|
};
|
|
70
141
|
}
|
|
@@ -140,7 +211,7 @@ export function createContentHandler(deps) {
|
|
|
140
211
|
const filePath = resolveContentPath(request.path);
|
|
141
212
|
if (filePath === undefined || isServiceWorkerPath(filePath))
|
|
142
213
|
return fail(404);
|
|
143
|
-
return serveFile(artifactId, release.manifest, filePath);
|
|
214
|
+
return serveFile(artifactId, release.manifest, filePath, request.range);
|
|
144
215
|
}
|
|
145
216
|
return {
|
|
146
217
|
async handle(request) {
|
package/dist/content/headers.js
CHANGED
|
@@ -17,10 +17,21 @@ const HTML_CSP = [
|
|
|
17
17
|
"style-src 'self' 'unsafe-inline'",
|
|
18
18
|
"img-src 'self' data:",
|
|
19
19
|
"connect-src 'self'",
|
|
20
|
+
"font-src 'self'",
|
|
21
|
+
"media-src 'self'",
|
|
20
22
|
"base-uri 'none'",
|
|
21
23
|
"form-action 'none'",
|
|
22
24
|
"frame-ancestors 'none'",
|
|
23
25
|
].join('; ');
|
|
26
|
+
/**
|
|
27
|
+
* Active-content types that can script or navigate when navigated to
|
|
28
|
+
* directly get a sandboxed CSP in addition to `nosniff`: SVG (validated at
|
|
29
|
+
* commit against scripts/handlers/external references, sandboxed at serve
|
|
30
|
+
* time so direct navigation cannot script even if a construct slips
|
|
31
|
+
* through) and PDF.
|
|
32
|
+
*/
|
|
33
|
+
const SANDBOX_CSP = "sandbox";
|
|
34
|
+
const SANDBOXED_MIME_TYPES = new Set(['image/svg+xml', 'application/pdf']);
|
|
24
35
|
/** Security/cache headers for one served file (declared MIME wins). */
|
|
25
36
|
export function contentHeaders(input) {
|
|
26
37
|
const mimeType = input.mimeType.length === 0 ? 'application/octet-stream' : input.mimeType;
|
|
@@ -36,6 +47,7 @@ export function contentHeaders(input) {
|
|
|
36
47
|
'x-frame-options': 'DENY',
|
|
37
48
|
'referrer-policy': 'no-referrer',
|
|
38
49
|
...(isHtml ? { 'content-security-policy': HTML_CSP } : {}),
|
|
50
|
+
...(SANDBOXED_MIME_TYPES.has(mimeType) ? { 'content-security-policy': SANDBOX_CSP } : {}),
|
|
39
51
|
};
|
|
40
52
|
}
|
|
41
53
|
/** Host-only grant cookie header value (no Domain attribute, ever). */
|
package/dist/http.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { type CompiledArtifactsProfile } from './profile/index.js';
|
|
2
2
|
import { type ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
3
3
|
import { type GuardedEnsureHost } from './server/service.js';
|
|
4
|
-
import { type
|
|
4
|
+
import { type IdempotencyStore } from './server/idempotency.js';
|
|
5
|
+
import { type KvPort, type PrincipalDirectoryPort, type SharingPolicyPort } from './server/ports.js';
|
|
5
6
|
import { type GuardedPublicationDeps, type PublicationService } from './server/publication.js';
|
|
6
|
-
import type
|
|
7
|
+
import { type StagingStore, type UploadSessionStore, type UploadSignerPort } from './server/uploads.js';
|
|
8
|
+
import type { ArtifactsMetrics } from './server/metrics.js';
|
|
9
|
+
import type { UploadPageStore } from './server/upload-page.js';
|
|
10
|
+
import { type AclStore } from './server/access.js';
|
|
11
|
+
import type { ArtifactReaderStore } from './server/reader-store.js';
|
|
7
12
|
import type { LifecycleService } from './server/lifecycle.js';
|
|
8
13
|
import { type ArtifactInvocationContext, type ArtifactCommitCoordinator } from './server/commit/types.js';
|
|
9
14
|
import { type ArtifactOutcome, type ArtifactHostFailureMapper } from './server/failures.js';
|
|
@@ -55,11 +60,36 @@ export interface HttpAppDeps {
|
|
|
55
60
|
sharingPolicy?: SharingPolicyPort;
|
|
56
61
|
/** G1: server-resolved platform admin predicate (never a tool argument). */
|
|
57
62
|
actorIsAdmin?: (actorId: string, storageScopeId: string) => boolean | Promise<boolean>;
|
|
63
|
+
/** G2: host principal directory; required for userRef resolution and output projection. */
|
|
64
|
+
directory?: PrincipalDirectoryPort;
|
|
65
|
+
/** Lot 1a: reader consent store; absent ⇒ consent routes fail closed with `capability_unavailable`. */
|
|
66
|
+
readerConsent?: ArtifactReaderStore;
|
|
58
67
|
/** One trusted URL policy shared by HTTP and MCP receipts: the artifact page and the exact version page. */
|
|
59
68
|
publicationUrls?: (artifactId: string, releaseId: string) => {
|
|
60
69
|
stableUrl: string;
|
|
61
70
|
versionUrl: string;
|
|
62
71
|
};
|
|
72
|
+
/** Files parity LOT 1: upload session ports, required when an upload capability is selected. */
|
|
73
|
+
uploads?: {
|
|
74
|
+
sessions: UploadSessionStore;
|
|
75
|
+
staging: StagingStore;
|
|
76
|
+
signer: UploadSignerPort;
|
|
77
|
+
idempotency?: IdempotencyStore;
|
|
78
|
+
/** LOT 2 §D: per-artifact staged TTL (host option, ceiling 7 days) and per-scope staging aggregate. */
|
|
79
|
+
stagedFileTtlMs?: number;
|
|
80
|
+
stagingQuotaBytesPerScope?: number;
|
|
81
|
+
/** LOT 2 §D.3: upload/storage metering; absent ⇒ no-op. */
|
|
82
|
+
metrics?: ArtifactsMetrics;
|
|
83
|
+
};
|
|
84
|
+
/** LOT 2 §A.5: browser upload page host wiring (required when `artifacts_create_upload_page` is selected). */
|
|
85
|
+
uploadPage?: {
|
|
86
|
+
/** Page ledger; absent ⇒ an in-memory ledger (single process only). */
|
|
87
|
+
pages?: UploadPageStore;
|
|
88
|
+
cookieSecret: string | Uint8Array;
|
|
89
|
+
controlOrigin: string;
|
|
90
|
+
pageBaseUrl: string;
|
|
91
|
+
s3Origins: readonly string[];
|
|
92
|
+
};
|
|
63
93
|
}
|
|
64
94
|
export interface ArtifactApp {
|
|
65
95
|
readonly selectedCapabilities: CompiledArtifactsProfile['selectedCapabilities'];
|