javascript-solid-server 0.0.207 → 0.0.208

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/bin/jss.js CHANGED
@@ -112,7 +112,7 @@ program
112
112
  .option('--cors-proxy-max-bytes <n>', 'CORS proxy upstream response size cap (default 50MB)', parseInt)
113
113
  .option('--cors-proxy-timeout-ms <ms>', 'CORS proxy upstream request timeout (default 30s)', parseInt)
114
114
  .option('--cors-proxy-max-redirects <n>', 'CORS proxy max redirect hops, each re-validated (default 5)', parseInt)
115
- .option('--body-limit <size>', 'Maximum request body size, e.g. 100MB or 1GB (default 10MB). Raise to accept larger `git push`; lower for tighter memory-DoS protection.')
115
+ .option('--body-limit <size>', 'Maximum request body size, e.g. 100MB or 1GB (default 20MB). Raise to accept larger `git push`; lower for tighter memory-DoS protection.')
116
116
  .option('--nostr', 'Enable Nostr relay')
117
117
  .option('--no-nostr', 'Disable Nostr relay')
118
118
  .option('--nostr-path <path>', 'Nostr relay WebSocket path (default: /relay)')
@@ -190,6 +190,10 @@ program
190
190
  const server = createServer({
191
191
  port: config.port,
192
192
  host: config.host,
193
+ // Wire the parsed --body-limit / JSS_BODY_LIMIT value through —
194
+ // omitting it here silently pinned every CLI-started server to
195
+ // the 10MB default and made the #474 knob dead wiring (#561).
196
+ bodyLimit: config.bodyLimit,
193
197
  logger: config.logger,
194
198
  conneg: config.conneg,
195
199
  notifications: config.notifications,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.207",
3
+ "version": "0.0.208",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/config.js CHANGED
@@ -20,11 +20,12 @@ export const defaults = {
20
20
  host: '0.0.0.0',
21
21
  root: './data',
22
22
  // Maximum request body size in bytes (or a size string when supplied
23
- // via CLI / config file, e.g. "100MB"). Default 10 MiB matches the
24
- // previous hard-coded Fastify limit. Operators hosting personal pods
25
- // may want to raise this so that large `git push` of an established
26
- // app repo doesn't 413 — see #474.
27
- bodyLimit: 10 * 1024 * 1024,
23
+ // via CLI / config file, e.g. "100MB"). 20 MiB default (#563) — a
24
+ // generous out-of-the-box limit for common workloads (larger `git
25
+ // push`, media uploads, bigger RDF documents). Raise via --body-limit
26
+ // / JSS_BODY_LIMIT for established app repos (#474); lower it for
27
+ // tighter memory-DoS protection.
28
+ bodyLimit: 20 * 1024 * 1024,
28
29
 
29
30
  // SSL
30
31
  sslKey: null,
@@ -279,7 +279,15 @@ export async function handleGit(request, reply) {
279
279
  CONTENT_TYPE: request.headers['content-type'] || '',
280
280
  QUERY_STRING: queryString,
281
281
  REMOTE_USER: request.webId || '', // Pass authenticated user
282
- CONTENT_LENGTH: request.headers['content-length'] || '0',
282
+ // Use the buffered body's real length, not the Content-Length header:
283
+ // git sends packs larger than http.postBuffer (1 MiB default) with
284
+ // Transfer-Encoding: chunked and NO Content-Length, so the header
285
+ // fallback told http-backend "0 bytes" and receive-pack died with
286
+ // "the remote end hung up unexpectedly" on any push > 1 MiB (#561).
287
+ // Fastify has already buffered the full body either way.
288
+ CONTENT_LENGTH: request.body?.length
289
+ ? String(request.body.length)
290
+ : (request.headers['content-length'] || '0'),
283
291
  };
284
292
 
285
293
  // For regular repositories, set GIT_DIR
package/src/server.js CHANGED
@@ -187,8 +187,8 @@ export function createServer(options = {}) {
187
187
  // already coerced by parseEnvValue) pass through unchanged; strings
188
188
  // ("100MB" from CLI / config files) go through parseSize for
189
189
  // size-shorthand support. The typeof check matters because parseSize
190
- // calls `.match` on its input and would throw on a raw number. Default
191
- // matches the previous hard-coded 10 MiB cap. See #474.
190
+ // calls `.match` on its input and would throw on a raw number. Falls
191
+ // back to defaults.bodyLimit (20 MiB, #563) when unset. See #474.
192
192
  const bodyLimit = options.bodyLimit == null
193
193
  ? defaults.bodyLimit
194
194
  : (typeof options.bodyLimit === 'number' ? options.bodyLimit : parseSize(options.bodyLimit));
@@ -0,0 +1,130 @@
1
+ /**
2
+ * CLI wiring for --body-limit / JSS_BODY_LIMIT (#561).
3
+ *
4
+ * test/body-limit.test.js covers createServer({ bodyLimit }) — the
5
+ * programmatic path — but the CLI start command builds its createServer
6
+ * options object by hand, and originally omitted `bodyLimit`. Result:
7
+ * the #474 knob parsed fine and was then silently dropped, pinning every
8
+ * CLI-started server to the 10 MiB default. git pushes of packs over the
9
+ * default failed with 413 no matter what the operator passed (#561).
10
+ *
11
+ * These tests spawn `bin/jss.js start` as a real subprocess (same
12
+ * pattern as cli-flag-like-values.test.js) and assert the limit
13
+ * actually reaches Fastify:
14
+ *
15
+ * - `--body-limit 1KB` → a 2 KiB PUT is rejected with 413
16
+ * - `--body-limit 5MB` → the same PUT is NOT rejected with 413
17
+ * - `JSS_BODY_LIMIT=1KB` (env, no flag) → 413, same as the flag
18
+ *
19
+ * The over-limit assertions are deliberately status-exact (413) while
20
+ * the under-limit assertion is only "not 413": body parsing runs before
21
+ * auth/WAC, so an under-limit request may still be refused later in the
22
+ * pipeline — that's fine, the wiring under test is the parser cap.
23
+ */
24
+
25
+ import { describe, it, afterEach } from 'node:test';
26
+ import assert from 'node:assert';
27
+ import { spawn } from 'node:child_process';
28
+ import { createServer as createNetServer } from 'node:net';
29
+ import { fileURLToPath } from 'node:url';
30
+ import path from 'node:path';
31
+ import fs from 'fs-extra';
32
+
33
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
34
+ const BIN = path.join(__dirname, '..', 'bin', 'jss.js');
35
+ const TEST_DATA_DIR = './test-data-body-limit-cli';
36
+
37
+ let child;
38
+
39
+ function freePort() {
40
+ return new Promise((resolve, reject) => {
41
+ const srv = createNetServer();
42
+ srv.once('error', reject);
43
+ srv.listen(0, '127.0.0.1', () => {
44
+ const { port } = srv.address();
45
+ srv.close(() => resolve(port));
46
+ });
47
+ });
48
+ }
49
+
50
+ async function startCli({ args = [], env = {} }) {
51
+ await fs.emptyDir(TEST_DATA_DIR);
52
+ const port = await freePort();
53
+ child = spawn(process.execPath, [
54
+ BIN, 'start',
55
+ '--port', String(port),
56
+ '--host', '127.0.0.1',
57
+ '--root', TEST_DATA_DIR,
58
+ ...args,
59
+ ], {
60
+ env: { ...process.env, ...env },
61
+ stdio: ['ignore', 'pipe', 'pipe'],
62
+ });
63
+ const baseUrl = `http://127.0.0.1:${port}`;
64
+
65
+ // Poll until the server answers (or the child dies / 15 s passes).
66
+ const deadline = Date.now() + 15_000;
67
+ let exited = false;
68
+ child.once('exit', () => { exited = true; });
69
+ while (Date.now() < deadline) {
70
+ if (exited) throw new Error('jss CLI exited before becoming ready');
71
+ try {
72
+ await fetch(baseUrl, { signal: AbortSignal.timeout(1000) });
73
+ return baseUrl;
74
+ } catch {
75
+ await new Promise(r => setTimeout(r, 250));
76
+ }
77
+ }
78
+ throw new Error('jss CLI did not become ready within 15s');
79
+ }
80
+
81
+ async function stopCli() {
82
+ if (!child) return;
83
+ const c = child;
84
+ child = null;
85
+ // The exitCode check and the once('exit') attach below are in the
86
+ // same synchronous block — Node can't emit 'exit' between two
87
+ // synchronous statements, so the listener can't miss the event (if
88
+ // it already fired, exitCode is non-null and we return here).
89
+ if (c.exitCode !== null || c.signalCode !== null) return;
90
+ const gone = new Promise(r => c.once('exit', r));
91
+ c.kill('SIGTERM');
92
+ await Promise.race([gone, new Promise(r => setTimeout(r, 3000))]);
93
+ if (c.exitCode === null && c.signalCode === null) c.kill('SIGKILL');
94
+ // SIGKILL can't be caught, so 'exit' follows promptly. The cap is a
95
+ // belt-and-braces bound so the suite can never hang on a pathological
96
+ // unkillable child (e.g. stuck in uninterruptible I/O).
97
+ await Promise.race([gone, new Promise(r => setTimeout(r, 2000))]);
98
+ }
99
+
100
+ async function putTwoKiB(baseUrl) {
101
+ const res = await fetch(`${baseUrl}/body-limit-probe.bin`, {
102
+ method: 'PUT',
103
+ headers: { 'Content-Type': 'application/octet-stream' },
104
+ body: Buffer.alloc(2048, 0x61),
105
+ signal: AbortSignal.timeout(5000),
106
+ });
107
+ return res.status;
108
+ }
109
+
110
+ describe('bin/jss.js — --body-limit reaches Fastify (#561)', () => {
111
+ afterEach(async () => {
112
+ await stopCli();
113
+ await fs.remove(TEST_DATA_DIR);
114
+ });
115
+
116
+ it('--body-limit 1KB rejects a 2KiB PUT with 413', async () => {
117
+ const baseUrl = await startCli({ args: ['--body-limit', '1KB'] });
118
+ assert.strictEqual(await putTwoKiB(baseUrl), 413);
119
+ });
120
+
121
+ it('--body-limit 5MB does not 413 a 2KiB PUT', async () => {
122
+ const baseUrl = await startCli({ args: ['--body-limit', '5MB'] });
123
+ assert.notStrictEqual(await putTwoKiB(baseUrl), 413);
124
+ });
125
+
126
+ it('JSS_BODY_LIMIT=1KB (env, no flag) rejects a 2KiB PUT with 413', async () => {
127
+ const baseUrl = await startCli({ env: { JSS_BODY_LIMIT: '1KB' } });
128
+ assert.strictEqual(await putTwoKiB(baseUrl), 413);
129
+ });
130
+ });
@@ -12,8 +12,8 @@
12
12
  *
13
13
  * Tests here verify the surface end-to-end — server actually rejects
14
14
  * over-size requests with 413, AND the size-string parsing path works
15
- * the same as the numeric path. The default (10 MiB) is covered
16
- * implicitly by every other test in the suite continuing to pass.
15
+ * the same as the numeric path. The out-of-the-box default (20 MiB
16
+ * since #563) is pinned explicitly via Fastify's initialConfig.
17
17
  */
18
18
 
19
19
  import { describe, it, before, after, afterEach } from 'node:test';
@@ -102,4 +102,14 @@ describe('configurable bodyLimit (#474)', () => {
102
102
  assert.notStrictEqual(res.status, 413,
103
103
  `100-byte body under a 10KB cap should not 413; got ${res.status}`);
104
104
  });
105
+
106
+ it('defaults to a 20 MiB body limit when none is configured (#563)', async () => {
107
+ await fs.emptyDir(TEST_DATA_DIR);
108
+ server = createServer({ logger: false, forceCloseConnections: true, root: TEST_DATA_DIR });
109
+ // Pin the EFFECTIVE wired default, not the constant in isolation:
110
+ // Fastify freezes resolved options into initialConfig, so this
111
+ // exercises config.defaults.bodyLimit → createServer → Fastify.
112
+ assert.strictEqual(server.initialConfig.bodyLimit, 20 * 1024 * 1024,
113
+ `expected the out-of-the-box default to be 20 MiB; got ${server.initialConfig.bodyLimit}`);
114
+ });
105
115
  });