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 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.
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { open } from 'node:fs/promises';
3
- import { setFileHeaders } from '../utils/headers.js';
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
- setFileHeaders(reply, { contentType: delivery.contentType, contentLength: body.length, etag });
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
- setFileHeaders(reply, delivery);
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,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAiBrD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,OAAuB,EACvB,KAAmB,EACnB,QAAuB,EACvB,EAAE,kBAAkB,EAAE,UAAU,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,GAAgB,EAAE,EAC1E,EAAE;IACF,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,EAA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AE,CAAC;QACvB,KAAK,CAAC,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { FastifyReply } from 'fastify';
2
- export declare const setFileHeaders: (reply: FastifyReply, metadata: {
2
+ export declare const setDeliveryHeaders: (reply: FastifyReply, metadata: {
3
3
  contentType: string;
4
4
  contentLength: number;
5
5
  etag?: string;
@@ -1,4 +1,9 @@
1
- export const setFileHeaders = (reply, metadata) => {
1
+ const contentSecurityPolicy = "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":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAmB,EACnB,QAA4F,EAC5F,EAAE;IACF,KAAK,CAAC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AC;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.7",
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.1153.0",
30
- "@aws-sdk/s3-request-presigner": "^3.1153.0",
31
- "@biomejs/biome": "^2.5.15",
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.8",
47
+ "dotenv": "^18.0.9",
48
48
  "fastify": "^5.12.7",
49
49
  "fastify-tsconfig": "^3.0.0",
50
- "knip": "^6.42.0",
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.11.2",
117
+ "packageManager": "pnpm@12.15.0",
118
118
  "peerDependenciesMeta": {
119
119
  "@aws-sdk/client-s3": {
120
120
  "optional": true
@@ -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 { setFileHeaders } from '../utils/headers.js';
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
- setFileHeaders(reply, { contentType: delivery.contentType, contentLength: body.length, etag });
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
- setFileHeaders(reply, delivery);
55
+ setDeliveryHeaders(reply, delivery);
56
56
  } catch (error) {
57
57
  body?.destroy();
58
58
  throw error;
@@ -1,16 +1,36 @@
1
1
  import type { FastifyReply } from 'fastify';
2
2
 
3
- export const setFileHeaders = (
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
  };