@ultimat3/storage 31.2.0 → 31.4.0
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/CLAUDE.md +1 -1
- package/README.md +8 -6
- package/package.json +2 -2
- package/src/attachment.ts +7 -1
- package/src/upload-scan.ts +12 -0
- package/src/upload-scanner.ts +10 -1
package/CLAUDE.md
CHANGED
|
@@ -145,7 +145,7 @@ Gotchas:
|
|
|
145
145
|
- **`serverSideEncryption` is declared and refused by BOTH drivers.** Full rule: `docs/history/storage.md`.
|
|
146
146
|
- **The `uploadScanner` port is the ONE scan path** (`As of 31.0.0`; the `quarantine: true` segment
|
|
147
147
|
and `releaseQuarantine` are retired). An out-of-band decision — a review, an async vendor scan —
|
|
148
|
-
is the verdict `hold`, keyed by `ScanInput.pendingKey
|
|
148
|
+
is the verdict `hold`, keyed by `(ScanInput.pendingKey, ScanInput.revision)` — the etag, or the bytes' sha256 (31.3; `pendingKey` alone cleared a rewrite): `X_STORAGE_QUARANTINED` (409), upload
|
|
149
149
|
kept pending, attempt deleted, no policy overrides it. A scanner that holds declares `holds: true`
|
|
150
150
|
(else its `hold` is `X_INVARIANT`), and its outage then refuses even under `'accept'`. A targeted
|
|
151
151
|
grant is refused while a scanner is installed (`X_STORAGE_TARGET_UNSCANNED`): it skips promotion.
|
package/README.md
CHANGED
|
@@ -515,7 +515,7 @@ export const runtime = {
|
|
|
515
515
|
} satisfies RuntimeOverrides;
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
-
`UploadScanner` (`@ultimat3/storage/adapter`) is `{ name, holds?, scan({ key, pendingKey, size, contentType, body }) }`,
|
|
518
|
+
`UploadScanner` (`@ultimat3/storage/adapter`) is `{ name, holds?, scan({ key, pendingKey, revision, size, contentType, body }) }`,
|
|
519
519
|
`body` a `ReadableStream`. `memoryUploadScanner()` is the reference: it flags the EICAR test string
|
|
520
520
|
(`EICAR_TEST_STRING`) anywhere in the stream, across chunk boundaries. Hold your adapter to the
|
|
521
521
|
contract with `behavesLike(uploadScannerConformance, () => yours)` from
|
|
@@ -526,20 +526,22 @@ latency budget are the app's (axiom 8). No scanner installed, nothing is scanned
|
|
|
526
526
|
|
|
527
527
|
Magic-byte sniffing closes stored XSS. It is **not** malware scanning: `application/zip` is the
|
|
528
528
|
OOXML container, so a macro-laden `.docx` passes `validateUpload` as a clean one does. A verdict
|
|
529
|
-
that is not ready inside the confirm is the scanner's `hold`, keyed by `pendingKey` —
|
|
530
|
-
own key, stable across retries (`key` is the per-attempt copy)
|
|
529
|
+
that is not ready inside the confirm is the scanner's `hold`, keyed by `(pendingKey, revision)` —
|
|
530
|
+
the upload's own key, stable across retries (`key` is the per-attempt copy), and WHICH bytes are
|
|
531
|
+
under it: the confirmed upload's etag, or `sha256:<hex>` on a disk with none. The upload URL stays
|
|
532
|
+
valid after the sniff, so a decision keyed by `pendingKey` alone clears whatever is PUT there next. One scan path; the v30
|
|
531
533
|
`grantUpload({ quarantine: true })` + `releaseQuarantine` flow is retired.
|
|
532
534
|
|
|
533
535
|
```ts
|
|
534
536
|
import type { UploadScanner } from '@ultimat3/storage/adapter';
|
|
535
537
|
|
|
536
538
|
// `approved` is your app's own store — a table a moderator's action writes.
|
|
537
|
-
export const reviewScanner = (approved: (
|
|
539
|
+
export const reviewScanner = (approved: (upload: string) => Promise<boolean>): UploadScanner => ({
|
|
538
540
|
name: 'review',
|
|
539
541
|
holds: true,
|
|
540
|
-
async scan({ pendingKey, body }) {
|
|
542
|
+
async scan({ pendingKey, revision, body }) {
|
|
541
543
|
await body.cancel();
|
|
542
|
-
return (await approved(pendingKey))
|
|
544
|
+
return (await approved(`${pendingKey}@${revision}`))
|
|
543
545
|
? { verdict: 'clean' }
|
|
544
546
|
: { verdict: 'hold', reason: 'awaiting a moderator' };
|
|
545
547
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/storage",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.4.0",
|
|
4
4
|
"description": "Named disks over Bun.file and Bun.s3: safe keys, signed URLs, sniffed uploads",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"test": "bun test"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ultimat3/core": "31.
|
|
46
|
+
"@ultimat3/core": "31.4.0"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/attachment.ts
CHANGED
|
@@ -223,7 +223,13 @@ async function scannedAttempt(
|
|
|
223
223
|
pending.etag === '' ? undefined : { ifMatch: pending.etag },
|
|
224
224
|
);
|
|
225
225
|
await assertCopyIsWhatWasJudged(disk, pending, attempt, input.policy);
|
|
226
|
-
await scanAttempt({
|
|
226
|
+
await scanAttempt({
|
|
227
|
+
disk,
|
|
228
|
+
pendingKey: input.key,
|
|
229
|
+
attempt,
|
|
230
|
+
revision: pending.etag,
|
|
231
|
+
policy: input.policy,
|
|
232
|
+
});
|
|
227
233
|
return attempt;
|
|
228
234
|
}
|
|
229
235
|
|
package/src/upload-scan.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ScanAttemptInput {
|
|
|
23
23
|
readonly pendingKey: string;
|
|
24
24
|
/** The attempt copy under `SCAN_SEGMENT`, already sniffed. */
|
|
25
25
|
readonly attempt: StorageObject;
|
|
26
|
+
/** The confirmed upload's etag; `''` when its disk keeps none, and the bytes are hashed instead. */
|
|
27
|
+
readonly revision: string;
|
|
26
28
|
readonly policy: UploadPolicy;
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -39,6 +41,14 @@ async function removeAll(disk: StorageDriver, keys: readonly string[]): Promise<
|
|
|
39
41
|
return removed;
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
/** `sha256:<hex>` of the attempt, streamed: the revision of an upload whose disk keeps no etag. */
|
|
45
|
+
async function digestOf(disk: StorageDriver, attempt: StorageObject): Promise<string> {
|
|
46
|
+
const hasher = new Bun.CryptoHasher('sha256');
|
|
47
|
+
const body = await disk.stream(attempt.key);
|
|
48
|
+
for await (const chunk of body) hasher.update(chunk);
|
|
49
|
+
return `sha256:${hasher.digest('hex')}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
/** True when a scanner is installed — `promoteAttachment` stages an attempt copy only then. */
|
|
43
53
|
export const scanning = (): boolean => uploadScanner() !== undefined;
|
|
44
54
|
|
|
@@ -57,10 +67,12 @@ export async function scanAttempt(input: ScanAttemptInput): Promise<void> {
|
|
|
57
67
|
try {
|
|
58
68
|
// Inside the `try`: an attempt that cannot be READ for the scanner (an S3 GET reset, an
|
|
59
69
|
// etag-pinned read refused) is no verdict too, never a raw error past the cleanup.
|
|
70
|
+
const revision = input.revision === '' ? await digestOf(disk, attempt) : input.revision;
|
|
60
71
|
body = await disk.stream(attempt.key, attempt.etag === '' ? undefined : { etag: attempt.etag });
|
|
61
72
|
verdict = await scanner.scan({
|
|
62
73
|
key: attempt.key,
|
|
63
74
|
pendingKey: input.pendingKey,
|
|
75
|
+
revision,
|
|
64
76
|
size: attempt.size,
|
|
65
77
|
contentType: attempt.contentType,
|
|
66
78
|
body,
|
package/src/upload-scanner.ts
CHANGED
|
@@ -14,6 +14,15 @@ export interface ScanInput {
|
|
|
14
14
|
* attempt.
|
|
15
15
|
*/
|
|
16
16
|
readonly pendingKey: string;
|
|
17
|
+
/**
|
|
18
|
+
* WHICH bytes under `pendingKey` this is: the confirmed upload's etag, or `sha256:<hex>` of the
|
|
19
|
+
* bytes on a disk that keeps none. The upload URL stays valid after the sniff, so the object under
|
|
20
|
+
* `pendingKey` can be rewritten between two confirms — a held verdict, and the decision that
|
|
21
|
+
* clears it, MUST be keyed by `(pendingKey, revision)`: an approval of one revision is no
|
|
22
|
+
* approval of the next. Always set by `promoteAttachment`; optional only so a scanner's own test
|
|
23
|
+
* written before 31.3 still compiles.
|
|
24
|
+
*/
|
|
25
|
+
readonly revision?: string | undefined;
|
|
17
26
|
readonly size: number;
|
|
18
27
|
/** The type the object is stored under, already sniffed against its bytes. */
|
|
19
28
|
readonly contentType: string;
|
|
@@ -28,7 +37,7 @@ export interface ScanInput {
|
|
|
28
37
|
*
|
|
29
38
|
* `hold` is a decision too: not yet cleared, by something outside this call — a human review, a
|
|
30
39
|
* vendor's asynchronous sandbox. The upload stays pending and promotion answers
|
|
31
|
-
* `X_STORAGE_QUARANTINED` until the scanner answers `clean` for that `pendingKey`. Neither `hold`
|
|
40
|
+
* `X_STORAGE_QUARANTINED` until the scanner answers `clean` for that `pendingKey` AND `revision`. Neither `hold`
|
|
32
41
|
* nor `infected` is something a policy can wave through.
|
|
33
42
|
*/
|
|
34
43
|
export type ScanVerdict =
|