@c9up/archive 0.1.13 → 0.1.15
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/dist/ArchiveProvider.d.ts +1 -0
- package/dist/ArchiveProvider.d.ts.map +1 -1
- package/dist/ArchiveProvider.js +53 -17
- package/dist/ArchiveProvider.js.map +1 -1
- package/dist/DriveManager.js +2 -2
- package/dist/DriveManager.js.map +1 -1
- package/dist/GcsDriver.js +5 -5
- package/dist/GcsDriver.js.map +1 -1
- package/dist/S3Driver.js +6 -6
- package/dist/S3Driver.js.map +1 -1
- package/dist/StaticMiddleware.d.ts.map +1 -1
- package/dist/StaticMiddleware.js +31 -11
- package/dist/StaticMiddleware.js.map +1 -1
- package/dist/StorageManager.d.ts +16 -8
- package/dist/StorageManager.d.ts.map +1 -1
- package/dist/StorageManager.js +176 -115
- package/dist/StorageManager.js.map +1 -1
- package/dist/etag.d.ts +32 -0
- package/dist/etag.d.ts.map +1 -0
- package/dist/etag.js +41 -0
- package/dist/etag.js.map +1 -0
- package/dist/expiry.d.ts +2 -2
- package/dist/expiry.js +6 -6
- package/dist/expiry.js.map +1 -1
- package/dist/services/main.d.ts +11 -0
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +21 -0
- package/dist/services/main.js.map +1 -1
- package/dist/testing/FakeStorage.js +7 -7
- package/dist/testing/FakeStorage.js.map +1 -1
- package/package.json +1 -1
- package/src/ArchiveProvider.ts +64 -24
- package/src/DriveManager.ts +2 -2
- package/src/GcsDriver.ts +5 -5
- package/src/S3Driver.ts +6 -6
- package/src/StaticMiddleware.ts +32 -11
- package/src/StorageManager.ts +182 -118
- package/src/etag.ts +44 -0
- package/src/expiry.ts +6 -6
- package/src/services/main.ts +21 -0
- package/src/testing/FakeStorage.ts +7 -7
package/src/StaticMiddleware.ts
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* @implements MISS-25
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { createHash } from "node:crypto";
|
|
14
13
|
import * as fs from "node:fs";
|
|
15
14
|
import * as fsp from "node:fs/promises";
|
|
16
15
|
import * as path from "node:path";
|
|
16
|
+
import { matchesIfNoneMatch, statTag } from "./etag.js";
|
|
17
17
|
import { DEFAULT_EXTENSIONS, inferMimeType } from "./mime-types.js";
|
|
18
18
|
import { VISIBILITY_SIDECAR_SUFFIX } from "./StorageManager.js";
|
|
19
19
|
|
|
@@ -142,13 +142,14 @@ export class StaticMiddleware {
|
|
|
142
142
|
return next();
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
// Quoted and weak (RFC 9110 §8.8.3): the bare md5 hex this used to send
|
|
146
|
+
// is not a valid entity-tag, and a strict cache may ignore it outright.
|
|
147
|
+
const etag = statTag(stat);
|
|
148
148
|
|
|
149
|
-
// ETag check — 304 Not Modified
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
// ETag check — 304 Not Modified. The header is a list compared weakly
|
|
150
|
+
// (§13.1.2); raw equality missed a client sending two tags, or one
|
|
151
|
+
// sending back `W/"x"` for a tag we wrote as `"x"`.
|
|
152
|
+
if (matchesIfNoneMatch(ctx.request.header("if-none-match"), etag)) {
|
|
152
153
|
ctx.response.status(304);
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
@@ -164,10 +165,30 @@ export class StaticMiddleware {
|
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
|
|
168
|
+
// Opened with O_NOFOLLOW rather than read by name.
|
|
169
|
+
//
|
|
170
|
+
// Reading the canonicalised path narrowed the window but did not close
|
|
171
|
+
// it: between `realpath` and the read, the last component of that path
|
|
172
|
+
// can be replaced by a symlink pointing anywhere, and a read by name
|
|
173
|
+
// follows it. Refusing to follow a link at open time takes the swap off
|
|
174
|
+
// the table — the open fails instead of serving a file outside the root.
|
|
175
|
+
//
|
|
176
|
+
// A parent directory swapped in the same window is not covered; that
|
|
177
|
+
// needs openat-relative-to-a-descriptor, which Node does not expose.
|
|
178
|
+
let content: Buffer;
|
|
179
|
+
try {
|
|
180
|
+
const handle = await fsp.open(
|
|
181
|
+
realPath,
|
|
182
|
+
fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW,
|
|
183
|
+
);
|
|
184
|
+
try {
|
|
185
|
+
content = await handle.readFile();
|
|
186
|
+
} finally {
|
|
187
|
+
await handle.close();
|
|
188
|
+
}
|
|
189
|
+
} catch {
|
|
190
|
+
return next();
|
|
191
|
+
}
|
|
171
192
|
// Send the raw Buffer — NOT content.toString() which would destroy binary
|
|
172
193
|
// data (PNG, PDF, ZIP, etc.) by interpreting it as UTF-8.
|
|
173
194
|
ctx.response.status(200).sendBuffer(content);
|