arocapi 5.0.0-beta.7 → 5.0.0-beta.8
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/README.md +10 -10
- package/dist/storage/deliver.js +3 -3
- package/dist/storage/deliver.js.map +1 -1
- package/dist/utils/headers.d.ts +1 -1
- package/dist/utils/headers.js +10 -1
- package/dist/utils/headers.js.map +1 -1
- package/package.json +7 -7
- package/src/storage/deliver.ts +3 -3
- package/src/utils/headers.ts +22 -2
package/README.md
CHANGED
|
@@ -38,16 +38,16 @@ pnpm dev # build and serve src/index.dev.ts on http://localhost:90
|
|
|
38
38
|
|
|
39
39
|
`.env` holds the local connection URLs and is committed, so don't put secrets in it.
|
|
40
40
|
|
|
41
|
-
| Command | What it does
|
|
42
|
-
| ----------------------------- |
|
|
43
|
-
| `pnpm lint` | Biome, type checking, the docs examples type check and knip
|
|
44
|
-
| `pnpm test` | Start the test containers, apply migrations and run every test
|
|
45
|
-
| `pnpm test src/app.test.ts` | Run one test file
|
|
46
|
-
| `pnpm test:watch` | Run the tests in watch mode
|
|
47
|
-
| `pnpm test:coverage` | Run the tests with an HTML coverage report
|
|
48
|
-
| `pnpm dbconsole` | Open a psql console on the development database
|
|
49
|
-
| `pnpm --filter website dev` | Run the documentation site locally
|
|
50
|
-
| `pnpm --filter website build` | Build the documentation site, checking its diagrams and every link
|
|
41
|
+
| Command | What it does |
|
|
42
|
+
| ----------------------------- | ------------------------------------------------------------------ |
|
|
43
|
+
| `pnpm lint` | Biome, type checking, the docs examples type check and knip |
|
|
44
|
+
| `pnpm test` | Start the test containers, apply migrations and run every test |
|
|
45
|
+
| `pnpm test src/app.test.ts` | Run one test file |
|
|
46
|
+
| `pnpm test:watch` | Run the tests in watch mode |
|
|
47
|
+
| `pnpm test:coverage` | Run the tests with an HTML coverage report |
|
|
48
|
+
| `pnpm dbconsole` | Open a psql console on the development database |
|
|
49
|
+
| `pnpm --filter website dev` | Run the documentation site locally |
|
|
50
|
+
| `pnpm --filter website build` | Build the documentation site, checking its diagrams and every link |
|
|
51
51
|
|
|
52
52
|
Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/); they decide the next version.
|
|
53
53
|
See [TESTING.md](TESTING.md) for the test setup and [RELEASING.md](RELEASING.md) for releases.
|
package/dist/storage/deliver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { open } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { setDeliveryHeaders } from '../utils/headers.js';
|
|
4
4
|
export const sendDelivery = async (request, reply, delivery, { contentDisposition, noRedirect = false, json = false } = {}) => {
|
|
5
5
|
if (delivery.type === 'redirect') {
|
|
6
6
|
return noRedirect ? reply.code(200).send({ location: delivery.url }) : reply.redirect(delivery.url, 302);
|
|
@@ -9,7 +9,7 @@ export const sendDelivery = async (request, reply, delivery, { contentDispositio
|
|
|
9
9
|
if (delivery.type === 'json' && json) {
|
|
10
10
|
const body = Buffer.from(JSON.stringify(delivery.value));
|
|
11
11
|
const etag = `"${createHash('sha256').update(body).digest('base64url')}"`;
|
|
12
|
-
|
|
12
|
+
setDeliveryHeaders(reply, { contentType: delivery.contentType, contentLength: body.length, etag });
|
|
13
13
|
return reply.code(200).send(head ? undefined : body);
|
|
14
14
|
}
|
|
15
15
|
if (delivery.type !== 'stream' && delivery.type !== 'path') {
|
|
@@ -20,7 +20,7 @@ export const sendDelivery = async (request, reply, delivery, { contentDispositio
|
|
|
20
20
|
body = delivery.type === 'stream' ? await delivery.open() : (await open(delivery.path)).createReadStream();
|
|
21
21
|
}
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
setDeliveryHeaders(reply, delivery);
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
26
|
body?.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deliver.js","sourceRoot":"","sources":["../../src/storage/deliver.ts"],"names":[],"mappings":"AAAA,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y = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
2
|
+
const token = "[!#$%&'*+\\-.^_`|~0-9a-z]+";
|
|
3
|
+
const quotedString = '"(?:[^"\\\\]|\\\\.)*"';
|
|
4
|
+
const mediaType = new RegExp(`^(?:audio|video)/${token}(?:[ \\t]*;[ \\t]*${token}=(?:${token}|${quotedString}))*[ \\t]*$`, 'i');
|
|
5
|
+
const isMedia = (contentType) => mediaType.test(contentType);
|
|
6
|
+
export const setDeliveryHeaders = (reply, metadata) => {
|
|
2
7
|
reply.header('Content-Type', metadata.contentType);
|
|
3
8
|
reply.header('Content-Length', metadata.contentLength.toString());
|
|
4
9
|
if (metadata.etag) {
|
|
@@ -7,5 +12,9 @@ export const setFileHeaders = (reply, metadata) => {
|
|
|
7
12
|
if (metadata.lastModified) {
|
|
8
13
|
reply.header('Last-Modified', metadata.lastModified.toUTCString());
|
|
9
14
|
}
|
|
15
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
16
|
+
if (!isMedia(metadata.contentType)) {
|
|
17
|
+
reply.header('Content-Security-Policy', contentSecurityPolicy);
|
|
18
|
+
}
|
|
10
19
|
};
|
|
11
20
|
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/utils/headers.ts"],"names":[],"mappings":"AAGA,MAAM,qBAAqB,GAAG,wDAAwD,CAAC;AAEvF,MAAM,KAAK,GAAG,4BAA4B,CAAC;AAC3C,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAC7C,MAAM,SAAS,GAAG,IAAI,MAAM,CAC1B,oBAAoB,KAAK,qBAAqB,KAAK,OAAO,KAAK,IAAI,YAAY,aAAa,EAC5F,GAAG,CACJ,CAAC;AAKF,MAAM,OAAO,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,KAAmB,EACnB,QAA4F,EAC5F,EAAE;IACF,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC1B,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;IAGD,KAAK,CAAC,MAAM,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACnC,KAAK,CAAC,MAAM,CAAC,yBAAyB,EAAE,qBAAqB,CAAC,CAAC;IACjE,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "arocapi",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.8",
|
|
5
5
|
"description": "An RO-Crate API",
|
|
6
6
|
"main": "dist/app.js",
|
|
7
7
|
"exports": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"zod": "^4.6.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@aws-sdk/client-s3": "^3.
|
|
30
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
31
|
-
"@biomejs/biome": "^2.
|
|
29
|
+
"@aws-sdk/client-s3": "^3.1157.0",
|
|
30
|
+
"@aws-sdk/s3-request-presigner": "^3.1157.0",
|
|
31
|
+
"@biomejs/biome": "^2.6.3",
|
|
32
32
|
"@commitlint/cli": "^21.2.4",
|
|
33
33
|
"@commitlint/config-conventional": "^21.2.4",
|
|
34
34
|
"@ocfl/ocfl-fs": "^0.4.0",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@vitest/ui": "^5.0.5",
|
|
45
45
|
"concurrently": "^10.0.6",
|
|
46
46
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
47
|
-
"dotenv": "^18.0.
|
|
47
|
+
"dotenv": "^18.0.9",
|
|
48
48
|
"fastify": "^5.12.7",
|
|
49
49
|
"fastify-tsconfig": "^3.0.0",
|
|
50
|
-
"knip": "^6.
|
|
50
|
+
"knip": "^6.43.0",
|
|
51
51
|
"lefthook": "^2.2.2",
|
|
52
52
|
"prisma": "^7.10.1",
|
|
53
53
|
"semantic-release": "^25.0.9",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"registry": "https://registry.npmjs.org/",
|
|
115
115
|
"provenance": true
|
|
116
116
|
},
|
|
117
|
-
"packageManager": "pnpm@12.
|
|
117
|
+
"packageManager": "pnpm@12.15.0",
|
|
118
118
|
"peerDependenciesMeta": {
|
|
119
119
|
"@aws-sdk/client-s3": {
|
|
120
120
|
"optional": true
|
package/src/storage/deliver.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { open } from 'node:fs/promises';
|
|
3
3
|
import type { Readable } from 'node:stream';
|
|
4
4
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
5
|
-
import {
|
|
5
|
+
import { setDeliveryHeaders } from '../utils/headers.js';
|
|
6
6
|
import type { ContentDelivery, JsonDelivery } from './backend.js';
|
|
7
7
|
|
|
8
8
|
type SendOptions = {
|
|
@@ -34,7 +34,7 @@ export const sendDelivery = async (
|
|
|
34
34
|
if (delivery.type === 'json' && json) {
|
|
35
35
|
const body = Buffer.from(JSON.stringify(delivery.value));
|
|
36
36
|
const etag = `"${createHash('sha256').update(body).digest('base64url')}"`;
|
|
37
|
-
|
|
37
|
+
setDeliveryHeaders(reply, { contentType: delivery.contentType, contentLength: body.length, etag });
|
|
38
38
|
|
|
39
39
|
return reply.code(200).send(head ? undefined : body);
|
|
40
40
|
}
|
|
@@ -52,7 +52,7 @@ export const sendDelivery = async (
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
|
|
55
|
+
setDeliveryHeaders(reply, delivery);
|
|
56
56
|
} catch (error) {
|
|
57
57
|
body?.destroy();
|
|
58
58
|
throw error;
|
package/src/utils/headers.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import type { FastifyReply } from 'fastify';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** Sandboxes deposited bytes; see docs/adr/0005-library-sandboxes-delivered-bytes.md */
|
|
4
|
+
const contentSecurityPolicy = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
5
|
+
|
|
6
|
+
const token = "[!#$%&'*+\\-.^_`|~0-9a-z]+";
|
|
7
|
+
const quotedString = '"(?:[^"\\\\]|\\\\.)*"';
|
|
8
|
+
const mediaType = new RegExp(
|
|
9
|
+
`^(?:audio|video)/${token}(?:[ \\t]*;[ \\t]*${token}=(?:${token}|${quotedString}))*[ \\t]*$`,
|
|
10
|
+
'i',
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
// Chrome won't play media opened directly under this CSP, and a media document can't run script.
|
|
14
|
+
// RFC 9110 grammar, so no comma outside quotes: browsers split the header as a list, respecting
|
|
15
|
+
// quotes, and take the last type, so `audio/mpeg, text/html` is HTML
|
|
16
|
+
const isMedia = (contentType: string) => mediaType.test(contentType);
|
|
17
|
+
|
|
18
|
+
export const setDeliveryHeaders = (
|
|
4
19
|
reply: FastifyReply,
|
|
5
20
|
metadata: { contentType: string; contentLength: number; etag?: string; lastModified?: Date },
|
|
6
21
|
) => {
|
|
7
22
|
reply.header('Content-Type', metadata.contentType);
|
|
8
23
|
reply.header('Content-Length', metadata.contentLength.toString());
|
|
9
|
-
|
|
10
24
|
if (metadata.etag) {
|
|
11
25
|
reply.header('ETag', metadata.etag);
|
|
12
26
|
}
|
|
13
27
|
if (metadata.lastModified) {
|
|
14
28
|
reply.header('Last-Modified', metadata.lastModified.toUTCString());
|
|
15
29
|
}
|
|
30
|
+
|
|
31
|
+
// Last, so a throw above can't leave them on the 500
|
|
32
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
33
|
+
if (!isMedia(metadata.contentType)) {
|
|
34
|
+
reply.header('Content-Security-Policy', contentSecurityPolicy);
|
|
35
|
+
}
|
|
16
36
|
};
|