@crvouga/mockingbird-service-s3 3.10.0 → 4.0.1
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 +17 -4
- package/DISCOVERY.md +3 -3
- package/README.md +32 -13
- package/dist/auth-v2-YGYT7VVQ.js +165 -0
- package/dist/auth-v2-YGYT7VVQ.js.map +7 -0
- package/dist/{chunk-5QCRU4MS.js → chunk-OLJWFVFY.js} +131 -1486
- package/dist/{chunk-5QCRU4MS.js.map → chunk-OLJWFVFY.js.map} +4 -4
- package/dist/chunk-T2XQWUBW.js +11338 -0
- package/dist/chunk-T2XQWUBW.js.map +7 -0
- package/dist/{chunk-SWLTKLTD.js → chunk-TOYOL22V.js} +6 -4
- package/dist/{chunk-SWLTKLTD.js.map → chunk-TOYOL22V.js.map} +1 -1
- package/dist/chunk-Y75YGK7R.js +1845 -0
- package/dist/chunk-Y75YGK7R.js.map +7 -0
- package/dist/cli.js +4 -2
- package/dist/cli.js.map +1 -1
- package/dist/digest-3YQZ27RJ.js +11 -0
- package/dist/digest-3YQZ27RJ.js.map +7 -0
- package/dist/index.d.ts +436 -299
- package/dist/index.js +3 -1
- package/dist/server.d.ts +239 -103
- package/dist/server.js +4 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
# Changelog — @crvouga/mockingbird-service-s3
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 4.0.1 (2026-11-02)
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Fixes and improvements
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- reopen IndexedDB durability connection after the browser force-closes it ([d0b45aa](https://github.com/crvouga/mockingbird/commit/d0b45aa1d12a55967e72b8ddc6573f5998c377ce))
|
|
8
|
+
- schedule packages whose tasks read another package's files ([7df459d](https://github.com/crvouga/mockingbird/commit/7df459d96132b4f84fa3553b1f907871c7e4f739))
|
|
9
9
|
|
|
10
10
|
### Dependencies
|
|
11
11
|
|
|
12
12
|
- `@crvouga/mockingbird-service-sqlite`
|
|
13
13
|
|
|
14
|
+
## 4.0.0 (2026-10-28)
|
|
15
|
+
|
|
16
|
+
### ⚠️ Breaking changes
|
|
17
|
+
|
|
18
|
+
- rebuild the S3 emulator to answer exactly as MinIO does ([ce30063](https://github.com/crvouga/mockingbird/commit/ce30063d2ef4cbdd1ef0991e836033a144261fcf))
|
|
19
|
+
|
|
20
|
+
## 3.10.0 (2026-10-24)
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
- add buffered SQL durability ([288bdcc](https://github.com/crvouga/mockingbird/commit/288bdcca84582787a54c4fdf9e803db9aac0b8d7))
|
|
25
|
+
- add efficient browser durability ([a8be579](https://github.com/crvouga/mockingbird/commit/a8be5799a883ddf6f731208e06f399410de4661a))
|
|
26
|
+
|
|
14
27
|
## 3.9.0 (2026-10-21)
|
|
15
28
|
|
|
16
29
|
### Features
|
package/DISCOVERY.md
CHANGED
|
@@ -21,11 +21,11 @@ consumer-side workaround.
|
|
|
21
21
|
|
|
22
22
|
## Parity and oracle
|
|
23
23
|
|
|
24
|
-
- Declared parity surface: **
|
|
24
|
+
- Declared parity surface: **Every MinIO S3 API, byte-exact against recorded MinIO transcripts**.
|
|
25
25
|
- Parity tier: **cold** (the repository controls when live checks run).
|
|
26
|
-
- Oracle: **
|
|
26
|
+
- Oracle: **Pinned self-hosted MinIO (RELEASE.2025-10-15T17-29-55Z) and its recorded transcripts**.
|
|
27
27
|
- Repository command: `bun run parity:service -- s3`.
|
|
28
|
-
- Evidence model:
|
|
28
|
+
- Evidence model: bun test replays every recorded MinIO transcript against the emulator offline; the live run needs a MinIO you start (packages/service/s3/oracle/README.md) and exits 2 when it is unreachable.
|
|
29
29
|
|
|
30
30
|
The npm package contains evidence summaries and the exact contract, not credentials or the
|
|
31
31
|
repository-only parity harness. Self-parity/property and acceptance tests run in the Mockingbird
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Local emulators. Real API contracts. Part of [Mockingbird](https://github.com/crvouga/mockingbird).
|
|
4
4
|
|
|
5
|
-
Stateful
|
|
5
|
+
Stateful S3 emulator that answers exactly as [MinIO](https://github.com/minio/minio) does, so it drops in for MinIO, Amazon S3 and other S3-compatible storage in tests. Every behavior is pinned by a differential oracle: 370 scripted scenarios (about 3,800 HTTP exchanges) were recorded against MinIO `RELEASE.2025-10-15T17-29-55Z`, and `bun test` replays each one against the emulator and requires the same status, headers and XML byte for byte.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -40,18 +40,37 @@ console.log(await object.Body?.transformToByteArray()) // Uint8Array(2) [ 0, 255
|
|
|
40
40
|
await server.close()
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Set an application's S3 endpoint environment variable to the server URL and its region to `us-east-1`.
|
|
43
|
+
Set an application's S3 endpoint environment variable to the server URL and its region to `us-east-1`.
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### Supported operations
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Everything MinIO's S3 router serves, with MinIO's precedence, validation order, error codes and messages (generated from MinIO's own error table):
|
|
48
48
|
|
|
49
|
-
- **
|
|
50
|
-
- **
|
|
51
|
-
- **
|
|
52
|
-
- **
|
|
53
|
-
- **
|
|
54
|
-
|
|
49
|
+
- **Buckets**: CreateBucket (location constraint, object-lock flag), HeadBucket, DeleteBucket (incl. `x-minio-force-delete`), ListBuckets, GetBucketLocation, Get/PutBucketVersioning (incl. MinIO's excluded prefixes), Get/Put/DeleteBucketPolicy and GetBucketPolicyStatus, Get/Put/DeleteBucketTagging, Get/Put/DeleteBucketLifecycle, Get/Put/DeleteBucketEncryption, Get/PutBucketNotification, Get/Put/DeleteBucketReplication, Get/PutObjectLockConfiguration, the ACL, website, accelerate, request-payment and logging stubs, and MinIO's ListenNotification and replication extensions.
|
|
50
|
+
- **Objects**: PutObject, GetObject, HeadObject (system and user metadata, conditional reads and writes, every Range form, `partNumber`, `response-*` overrides, checksums CRC32/CRC32C/CRC64NVME/SHA1/SHA256 with `x-amz-checksum-mode`), CopyObject (metadata and tagging directives, copy-source conditionals, versions), DeleteObject and DeleteObjects (delete markers, null versions), Get/Put/DeleteObjectTagging, Get/PutObjectRetention, Get/PutObjectLegalHold, Get/PutObjectAcl, GetObjectAttributes, RestoreObject, SelectObjectContent (CSV and JSON input, basic SQL, event-stream framing), and browser POST uploads (POST policy, V4 and V2 form signatures).
|
|
51
|
+
- **Listing**: ListObjects V1, V2 and `metadata=true`, ListObjectVersions, including MinIO's marker and truncation behavior.
|
|
52
|
+
- **Multipart**: Create, UploadPart, UploadPartCopy, Complete, Abort, ListParts, ListMultipartUploads, with part checksums and the `<md5>-N` ETag.
|
|
53
|
+
- **Authentication**: SigV4 header and presigned, streaming `aws-chunked` (signed chunks and signed or unsigned trailers), SigV2 header and presigned, request-time skew, and anonymous access through bucket policies.
|
|
54
|
+
|
|
55
|
+
`GetObjectLambda` and `PutObjectExtract` (snowball auto-extract) answer `NotImplemented`.
|
|
56
|
+
|
|
57
|
+
### Authentication modes
|
|
58
|
+
|
|
59
|
+
- `authentication: "lenient"` (default): unsigned requests act as the bucket owner and header signatures are not checked, so plain `fetch` works in tests. Presigned URLs are still verified against `credentials` (default `fixture` / `fixture`).
|
|
60
|
+
- `authentication: "strict"`: MinIO's authentication exactly. Every request must be signed by a key in `credentials`, and an anonymous request is allowed only where the bucket policy grants it. The oracle runs in this mode.
|
|
61
|
+
|
|
62
|
+
`region` (default `us-east-1`) is the signing region and the `x-amz-bucket-region` header.
|
|
63
|
+
|
|
64
|
+
### Where it departs from MinIO
|
|
65
|
+
|
|
66
|
+
- **Bucket CORS**: MinIO only stubs the bucket CORS API, so the emulator keeps Amazon S3's documented behavior. The stored `CORSConfiguration` is enforced: a preflight is answered by the first matching rule or refused with `403 AccessForbidden`, and matching actual requests get `Access-Control-*` headers. This is not oracle-verified.
|
|
67
|
+
- **Virtual-hosted-style addressing**: `Host: <bucket>.<base host>` names the bucket (base hosts default to `localhost`; set `virtualHosts`, or `--virtual-host a,b`, empty for path-style only).
|
|
68
|
+
- **Body size**: `createServer` accepts up to 5 GiB per PUT or part (S3's limit; MinIO's is 5 TiB). `createServer({ maxBodyBytes })` lowers it.
|
|
69
|
+
- **Listings** always read live data, where MinIO serves later pages from a snapshot taken on the first page.
|
|
70
|
+
|
|
71
|
+
### The oracle
|
|
72
|
+
|
|
73
|
+
`oracle/` in the repository holds the harness, the scenarios and the recorded MinIO transcripts. `bun oracle/run.ts` replays them against a live MinIO, `--record` refreshes the transcripts; see [oracle/README.md](https://github.com/crvouga/mockingbird/tree/main/packages/service/s3/oracle).
|
|
55
74
|
|
|
56
75
|
### Admin and deterministic controls
|
|
57
76
|
|
|
@@ -65,16 +84,16 @@ The shared runtime also provides health, reset, journal, metrics, timeline, and
|
|
|
65
84
|
|
|
66
85
|
### Deliberately not modelled
|
|
67
86
|
|
|
68
|
-
|
|
87
|
+
SSE-C and SSE-KMS encryption (MinIO needs TLS and a KMS for them), IAM users and policies other than the root credentials and bucket policies, actually applying lifecycle rules or replicating, and real SQS delivery. SQS consumers can use the captured notification payload through a configured HTTP sink.
|
|
69
88
|
|
|
70
89
|
## API
|
|
71
90
|
|
|
72
91
|
- `S3API`, `S3APIOptions`: Fetch handler and configuration.
|
|
73
|
-
- `S3Notification`, `S3Object`, `
|
|
92
|
+
- `S3Notification`, `S3Object` (`ObjectVersion`), `S3SeedObject`, `BucketRecord`, `MultipartUpload`, `MultipartPart`: notification, state, and fixture types.
|
|
74
93
|
- `createRuntime`, `S3Runtime`, `S3RuntimeOptions`: full Mockingbird runtime and webhook hub.
|
|
75
94
|
- `S3_NAMESPACE`, `S3_PRESETS`, `accessKeyCredential`: constants and fault controls.
|
|
76
95
|
- `S3_MAX_UPLOAD_BYTES`: the default request body limit (5 GiB) for `createServer`.
|
|
77
96
|
- `document`, `operationIds`, `supportedOperationIds`: generated OpenAPI metadata.
|
|
78
97
|
- `createServer`, `S3ServerOptions`, `DEFAULT_PORT`, `serveTarget` from `./server`: Node HTTP adapter and CLI integration.
|
|
79
98
|
|
|
80
|
-
|
|
99
|
+
Oracle: [MinIO](https://github.com/minio/minio) `RELEASE.2025-10-15T17-29-55Z`, with the [Amazon S3 API Reference](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html) for bucket CORS.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SIGN_V4,
|
|
3
|
+
checkKey,
|
|
4
|
+
fail,
|
|
5
|
+
hmacRaw
|
|
6
|
+
} from "./chunk-Y75YGK7R.js";
|
|
7
|
+
|
|
8
|
+
// src/auth-v2.ts
|
|
9
|
+
var encoder = new TextEncoder();
|
|
10
|
+
var RESOURCES = [
|
|
11
|
+
"acl",
|
|
12
|
+
"cors",
|
|
13
|
+
"delete",
|
|
14
|
+
"encryption",
|
|
15
|
+
"legal-hold",
|
|
16
|
+
"lifecycle",
|
|
17
|
+
"location",
|
|
18
|
+
"logging",
|
|
19
|
+
"notification",
|
|
20
|
+
"partNumber",
|
|
21
|
+
"policy",
|
|
22
|
+
"requestPayment",
|
|
23
|
+
"response-cache-control",
|
|
24
|
+
"response-content-disposition",
|
|
25
|
+
"response-content-encoding",
|
|
26
|
+
"response-content-language",
|
|
27
|
+
"response-content-type",
|
|
28
|
+
"response-expires",
|
|
29
|
+
"retention",
|
|
30
|
+
"select",
|
|
31
|
+
"select-type",
|
|
32
|
+
"tagging",
|
|
33
|
+
"torrent",
|
|
34
|
+
"uploadId",
|
|
35
|
+
"uploads",
|
|
36
|
+
"versionId",
|
|
37
|
+
"versioning",
|
|
38
|
+
"versions",
|
|
39
|
+
"website"
|
|
40
|
+
];
|
|
41
|
+
var base64 = (bytes) => btoa(String.fromCharCode(...bytes));
|
|
42
|
+
var queryUnescape = (value) => {
|
|
43
|
+
if (/%(?![0-9A-Fa-f]{2})/.test(value)) return void 0;
|
|
44
|
+
try {
|
|
45
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
46
|
+
} catch {
|
|
47
|
+
return value.replace(/\+/g, " ").replace(
|
|
48
|
+
/%([0-9A-Fa-f]{2})/g,
|
|
49
|
+
(_, code) => String.fromCharCode(Number.parseInt(code, 16))
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var unescapeQueries = (rawQuery) => {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const query of rawQuery.split("&")) {
|
|
56
|
+
const value = queryUnescape(query);
|
|
57
|
+
if (value === void 0) fail("InvalidQueryParams");
|
|
58
|
+
out.push(value);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
};
|
|
62
|
+
var canonicalAmzHeaders = (headers) => {
|
|
63
|
+
const lines = [];
|
|
64
|
+
for (const [name, value] of headers) if (name.startsWith("x-amz-")) lines.push([name, value]);
|
|
65
|
+
return lines.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, value]) => `${name}:${value}`).join("\n");
|
|
66
|
+
};
|
|
67
|
+
var canonicalResource = (resource, query) => {
|
|
68
|
+
const values = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const entry of query.split("&")) {
|
|
70
|
+
const index = entry.indexOf("=");
|
|
71
|
+
if (index < 0) values.set(entry, "");
|
|
72
|
+
else values.set(entry.slice(0, index), entry.slice(index + 1));
|
|
73
|
+
}
|
|
74
|
+
const parts = [];
|
|
75
|
+
for (const name of RESOURCES) {
|
|
76
|
+
const value = values.get(name);
|
|
77
|
+
if (value === void 0) continue;
|
|
78
|
+
parts.push(value === "" ? name : `${name}=${value}`);
|
|
79
|
+
}
|
|
80
|
+
return parts.length ? `${resource}?${parts.join("&")}` : resource;
|
|
81
|
+
};
|
|
82
|
+
var stringToSign = (request, query, date) => {
|
|
83
|
+
let amz = canonicalAmzHeaders(request.headers);
|
|
84
|
+
if (amz) amz += "\n";
|
|
85
|
+
return [
|
|
86
|
+
request.method,
|
|
87
|
+
request.headers.get("content-md5") ?? "",
|
|
88
|
+
request.headers.get("content-type") ?? "",
|
|
89
|
+
date,
|
|
90
|
+
amz
|
|
91
|
+
].join("\n") + canonicalResource(request.rawPath, query);
|
|
92
|
+
};
|
|
93
|
+
var sign = async (secret, value) => base64(await hmacRaw("SHA-1", encoder.encode(secret), value));
|
|
94
|
+
var decode64 = (value) => {
|
|
95
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value))
|
|
96
|
+
return void 0;
|
|
97
|
+
return atob(value);
|
|
98
|
+
};
|
|
99
|
+
var sameSignature = (a, b) => {
|
|
100
|
+
const left = decode64(a);
|
|
101
|
+
const right = decode64(b);
|
|
102
|
+
return left !== void 0 && right !== void 0 && left === right;
|
|
103
|
+
};
|
|
104
|
+
var requestAccessKeyV2 = (request, lookup) => {
|
|
105
|
+
const presigned = request.query.get("AWSAccessKeyId");
|
|
106
|
+
if (presigned) {
|
|
107
|
+
checkKey(lookup, presigned);
|
|
108
|
+
return presigned;
|
|
109
|
+
}
|
|
110
|
+
const fields = (request.headers.get("authorization") ?? "").split(" ");
|
|
111
|
+
if (fields.length !== 2) fail("MissingFields");
|
|
112
|
+
const keySign = fields[1].trim().split(":");
|
|
113
|
+
if (keySign.length !== 2) fail("MissingFields");
|
|
114
|
+
checkKey(lookup, keySign[0]);
|
|
115
|
+
return keySign[0];
|
|
116
|
+
};
|
|
117
|
+
var verifyHeaderV2 = async (request, lookup) => {
|
|
118
|
+
const header = request.headers.get("authorization") ?? "";
|
|
119
|
+
if (!header) fail("AuthHeaderEmpty");
|
|
120
|
+
if (!header.startsWith("AWS") || header.startsWith(SIGN_V4)) fail("SignatureVersionNotSupported");
|
|
121
|
+
const accessKey = requestAccessKeyV2(request, lookup);
|
|
122
|
+
const secret = checkKey(lookup, accessKey);
|
|
123
|
+
const queries = unescapeQueries(request.rawQuery);
|
|
124
|
+
const prefix = `AWS ${accessKey}:`;
|
|
125
|
+
if (!header.startsWith(prefix)) fail("SignatureDoesNotMatch");
|
|
126
|
+
const expected = await sign(
|
|
127
|
+
secret,
|
|
128
|
+
stringToSign(request, queries.join("&"), request.headers.get("date") ?? "")
|
|
129
|
+
);
|
|
130
|
+
if (!sameSignature(header.slice(prefix.length), expected)) fail("SignatureDoesNotMatch");
|
|
131
|
+
return accessKey;
|
|
132
|
+
};
|
|
133
|
+
var verifyPresignV2 = async (request, lookup, now) => {
|
|
134
|
+
const filtered = [];
|
|
135
|
+
let signature = "";
|
|
136
|
+
let expires = "";
|
|
137
|
+
let accessKey = "";
|
|
138
|
+
for (const query of unescapeQueries(request.rawQuery)) {
|
|
139
|
+
const index = query.indexOf("=");
|
|
140
|
+
if (index < 0) fail("InvalidQueryParams");
|
|
141
|
+
const name = query.slice(0, index);
|
|
142
|
+
const value = query.slice(index + 1);
|
|
143
|
+
if (name === "AWSAccessKeyId") accessKey = value;
|
|
144
|
+
else if (name === "Signature") signature = value;
|
|
145
|
+
else if (name === "Expires") expires = value;
|
|
146
|
+
else filtered.push(query);
|
|
147
|
+
}
|
|
148
|
+
if (!accessKey || !signature || !expires) fail("InvalidQueryParams");
|
|
149
|
+
const secret = checkKey(lookup, accessKey);
|
|
150
|
+
if (!/^[+-]?\d+$/.test(expires)) fail("MalformedExpires");
|
|
151
|
+
if (Number(expires) < Math.floor(now / 1e3)) fail("ExpiredPresignRequest");
|
|
152
|
+
const expected = await sign(secret, stringToSign(request, filtered.join("&"), expires));
|
|
153
|
+
if (!sameSignature(signature, expected)) fail("SignatureDoesNotMatch");
|
|
154
|
+
return accessKey;
|
|
155
|
+
};
|
|
156
|
+
var verifyV2 = async (request, lookup, now, presigned) => {
|
|
157
|
+
if (presigned) await verifyPresignV2(request, lookup, now);
|
|
158
|
+
else await verifyHeaderV2(request, lookup);
|
|
159
|
+
return requestAccessKeyV2(request, lookup);
|
|
160
|
+
};
|
|
161
|
+
export {
|
|
162
|
+
requestAccessKeyV2,
|
|
163
|
+
verifyV2
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=auth-v2-YGYT7VVQ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/auth-v2.ts"],
|
|
4
|
+
"sourcesContent": ["/** AWS Signature Version 2 (header and presigned), as MinIO's `cmd/signature-v2.go` checks it. */\nimport { checkKey, hmacRaw, type Lookup, SIGN_V4, type SignedRequest } from \"./auth.js\"\nimport { fail } from \"./errors.js\"\n\nconst encoder = new TextEncoder()\n\n/** The sub-resources a V2 signature covers, in MinIO's `resourceList` order. */\nconst RESOURCES = [\n \"acl\",\n \"cors\",\n \"delete\",\n \"encryption\",\n \"legal-hold\",\n \"lifecycle\",\n \"location\",\n \"logging\",\n \"notification\",\n \"partNumber\",\n \"policy\",\n \"requestPayment\",\n \"response-cache-control\",\n \"response-content-disposition\",\n \"response-content-encoding\",\n \"response-content-language\",\n \"response-content-type\",\n \"response-expires\",\n \"retention\",\n \"select\",\n \"select-type\",\n \"tagging\",\n \"torrent\",\n \"uploadId\",\n \"uploads\",\n \"versionId\",\n \"versioning\",\n \"versions\",\n \"website\",\n]\n\nconst base64 = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes))\n\n/** Go's `url.QueryUnescape`: `+` is a space, a bad `%` escape is an error (`undefined`). */\nconst queryUnescape = (value: string) => {\n if (/%(?![0-9A-Fa-f]{2})/.test(value)) return undefined\n try {\n return decodeURIComponent(value.replace(/\\+/g, \" \"))\n } catch {\n // Go keeps invalid UTF-8 bytes; decode them one by one.\n return value\n .replace(/\\+/g, \" \")\n .replace(/%([0-9A-Fa-f]{2})/g, (_, code: string) =>\n String.fromCharCode(Number.parseInt(code, 16)),\n )\n }\n}\n\nconst unescapeQueries = (rawQuery: string) => {\n const out: string[] = []\n for (const query of rawQuery.split(\"&\")) {\n const value = queryUnescape(query)\n if (value === undefined) fail(\"InvalidQueryParams\")\n out.push(value as string)\n }\n return out\n}\n\n/** `x-amz-*` headers, lowercased, sorted, multi-values joined with `,`. */\nconst canonicalAmzHeaders = (headers: Headers) => {\n const lines: [string, string][] = []\n for (const [name, value] of headers) if (name.startsWith(\"x-amz-\")) lines.push([name, value])\n return lines\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n .map(([name, value]) => `${name}:${value}`)\n .join(\"\\n\")\n}\n\nconst canonicalResource = (resource: string, query: string) => {\n const values = new Map<string, string>()\n for (const entry of query.split(\"&\")) {\n const index = entry.indexOf(\"=\")\n if (index < 0) values.set(entry, \"\")\n else values.set(entry.slice(0, index), entry.slice(index + 1))\n }\n const parts: string[] = []\n for (const name of RESOURCES) {\n const value = values.get(name)\n if (value === undefined) continue\n parts.push(value === \"\" ? name : `${name}=${value}`)\n }\n return parts.length ? `${resource}?${parts.join(\"&\")}` : resource\n}\n\nconst stringToSign = (request: SignedRequest, query: string, date: string) => {\n let amz = canonicalAmzHeaders(request.headers)\n if (amz) amz += \"\\n\"\n return (\n [\n request.method,\n request.headers.get(\"content-md5\") ?? \"\",\n request.headers.get(\"content-type\") ?? \"\",\n date,\n amz,\n ].join(\"\\n\") + canonicalResource(request.rawPath, query)\n )\n}\n\nconst sign = async (secret: string, value: string) =>\n base64(await hmacRaw(\"SHA-1\", encoder.encode(secret), value))\n\n/** Go's `base64.StdEncoding.DecodeString`, or undefined. */\nconst decode64 = (value: string) => {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value))\n return undefined\n return atob(value)\n}\nconst sameSignature = (a: string, b: string) => {\n const left = decode64(a)\n const right = decode64(b)\n return left !== undefined && right !== undefined && left === right\n}\n\n/** MinIO's `getReqAccessKeyV2`: the presigned `AWSAccessKeyId`, else `AWS <key>:<signature>`. */\nexport const requestAccessKeyV2 = (request: SignedRequest, lookup: Lookup) => {\n const presigned = request.query.get(\"AWSAccessKeyId\")\n if (presigned) {\n checkKey(lookup, presigned)\n return presigned\n }\n const fields = (request.headers.get(\"authorization\") ?? \"\").split(\" \")\n if (fields.length !== 2) fail(\"MissingFields\")\n const keySign = (fields[1] as string).trim().split(\":\")\n if (keySign.length !== 2) fail(\"MissingFields\")\n checkKey(lookup, keySign[0] as string)\n return keySign[0] as string\n}\n\n/** MinIO's `doesSignV2Match`. */\nconst verifyHeaderV2 = async (request: SignedRequest, lookup: Lookup) => {\n const header = request.headers.get(\"authorization\") ?? \"\"\n if (!header) fail(\"AuthHeaderEmpty\")\n if (!header.startsWith(\"AWS\") || header.startsWith(SIGN_V4)) fail(\"SignatureVersionNotSupported\")\n const accessKey = requestAccessKeyV2(request, lookup)\n const secret = checkKey(lookup, accessKey)\n const queries = unescapeQueries(request.rawQuery)\n const prefix = `AWS ${accessKey}:`\n if (!header.startsWith(prefix)) fail(\"SignatureDoesNotMatch\")\n const expected = await sign(\n secret,\n stringToSign(request, queries.join(\"&\"), request.headers.get(\"date\") ?? \"\"),\n )\n if (!sameSignature(header.slice(prefix.length), expected)) fail(\"SignatureDoesNotMatch\")\n return accessKey\n}\n\n/** MinIO's `doesPresignV2SignatureMatch`. */\nconst verifyPresignV2 = async (request: SignedRequest, lookup: Lookup, now: number) => {\n const filtered: string[] = []\n let signature = \"\"\n let expires = \"\"\n let accessKey = \"\"\n for (const query of unescapeQueries(request.rawQuery)) {\n const index = query.indexOf(\"=\")\n if (index < 0) fail(\"InvalidQueryParams\")\n const name = query.slice(0, index)\n const value = query.slice(index + 1)\n if (name === \"AWSAccessKeyId\") accessKey = value\n else if (name === \"Signature\") signature = value\n else if (name === \"Expires\") expires = value\n else filtered.push(query)\n }\n if (!accessKey || !signature || !expires) fail(\"InvalidQueryParams\")\n const secret = checkKey(lookup, accessKey)\n if (!/^[+-]?\\d+$/.test(expires)) fail(\"MalformedExpires\")\n if (Number(expires) < Math.floor(now / 1000)) fail(\"ExpiredPresignRequest\")\n const expected = await sign(secret, stringToSign(request, filtered.join(\"&\"), expires))\n if (!sameSignature(signature, expected)) fail(\"SignatureDoesNotMatch\")\n return accessKey\n}\n\n/** MinIO's `isReqAuthenticatedV2` then `getReqAccessKeyV2`: the verified access key. */\nexport const verifyV2 = async (\n request: SignedRequest,\n lookup: Lookup,\n now: number,\n presigned: boolean,\n): Promise<string> => {\n if (presigned) await verifyPresignV2(request, lookup, now)\n else await verifyHeaderV2(request, lookup)\n return requestAccessKeyV2(request, lookup)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,IAAM,UAAU,IAAI,YAAY;AAGhC,IAAM,YAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,SAAS,CAAC,UAAsB,KAAK,OAAO,aAAa,GAAG,KAAK,CAAC;AAGxE,IAAM,gBAAgB,CAAC,UAAkB;AACvC,MAAI,sBAAsB,KAAK,KAAK,EAAG,QAAO;AAC9C,MAAI;AACF,WAAO,mBAAmB,MAAM,QAAQ,OAAO,GAAG,CAAC;AAAA,EACrD,QAAQ;AAEN,WAAO,MACJ,QAAQ,OAAO,GAAG,EAClB;AAAA,MAAQ;AAAA,MAAsB,CAAC,GAAG,SACjC,OAAO,aAAa,OAAO,SAAS,MAAM,EAAE,CAAC;AAAA,IAC/C;AAAA,EACJ;AACF;AAEA,IAAM,kBAAkB,CAAC,aAAqB;AAC5C,QAAM,MAAgB,CAAC;AACvB,aAAW,SAAS,SAAS,MAAM,GAAG,GAAG;AACvC,UAAM,QAAQ,cAAc,KAAK;AACj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