javascript-solid-server 0.0.205 → 0.0.207
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/.claude/settings.local.json +31 -1
- package/README.md +2 -1
- package/bin/jss.js +1 -0
- package/package.json +7 -2
- package/src/config.js +9 -2
- package/src/handlers/git.js +6 -4
- package/src/handlers/resource.js +188 -4
- package/src/idp/index.js +5 -1
- package/src/idp/interactions.js +96 -25
- package/src/idp/provider.js +11 -0
- package/src/idp/views.js +25 -2
- package/src/idp/well-known-did-nostr.js +44 -7
- package/src/index.js +2 -1
- package/src/server.js +26 -6
- package/src/tunnel/index.js +95 -10
- package/test/body-limit.test.js +105 -0
- package/test/git-auto-init.test.js +10 -0
- package/test/git-handler.test.js +239 -0
- package/test/head-conneg.test.js +249 -0
- package/test/idp-issuer-normalization.test.js +100 -0
- package/test/idp-login-error.test.js +155 -0
- package/test/passkey-webauthn-degrade.test.js +118 -0
- package/test/schnorr-complete-defensive.test.js +163 -0
- package/test/tunnel.test.js +166 -0
- package/test/well-known-did-nostr.test.js +63 -0
|
@@ -22,7 +22,37 @@
|
|
|
22
22
|
"Bash(git commit -q -m 'fix\\(rdf\\): preserve blank-node SUBJECTS through Turtle ↔ JSON-LD \\(#536\\) *)",
|
|
23
23
|
"Bash(npm view *)",
|
|
24
24
|
"Bash(git branch *)",
|
|
25
|
-
"Bash(git commit -q -m 'bump version to 0.0.205 *)"
|
|
25
|
+
"Bash(git commit -q -m 'bump version to 0.0.205 *)",
|
|
26
|
+
"Bash(gh repo *)",
|
|
27
|
+
"Bash(curl -sL https://raw.githubusercontent.com/JavaScriptSolidServer/solid-oidc/gh-pages/example.html)",
|
|
28
|
+
"Bash(curl -sL https://raw.githubusercontent.com/JavaScriptSolidServer/solid-oidc/gh-pages/solid-oidc.js)",
|
|
29
|
+
"Bash(mkdir -p /tmp/jss-sanity-23)",
|
|
30
|
+
"Read(//tmp/**)",
|
|
31
|
+
"Bash(DATA_ROOT=. node /home/melvin/remote/github.com/JavaScriptSolidServer/JavaScriptSolidServer/bin/jss.js start --idp --conneg --port 4901 --quiet)",
|
|
32
|
+
"Bash(curl -si -c /tmp/jss-sanity-cookies.txt -b /tmp/jss-sanity-cookies.txt \"http://localhost:4901/idp/interaction/Qp-9Nn6O9Rv79dlCsI9YWGlXNZZswTi4UUJ2PjXt4x3\")",
|
|
33
|
+
"Bash(curl -s -c /tmp/jss-sanity-cookies.txt -b /tmp/jss-sanity-cookies.txt \"http://localhost:4901/idp/interaction/Qp-9Nn6O9Rv79dlCsI9YWGlXNZZswTi4UUJ2PjXt4x3\")",
|
|
34
|
+
"Bash(kill bx5n5fpi1 *)",
|
|
35
|
+
"Bash(pkill -f \"jss.js start --idp --port 4901\")",
|
|
36
|
+
"Bash(rm -f /tmp/jss-sanity-cookies.txt)",
|
|
37
|
+
"Bash(rm -rf /tmp/jss-sanity-23)",
|
|
38
|
+
"Bash(gh label *)",
|
|
39
|
+
"Bash(git commit -q -m 'fix\\(idp\\): handleSchnorrComplete recovers from interactionFinished throw — no more 504 hang \\(#412\\) *)",
|
|
40
|
+
"Bash(sed -n '163,170p' src/idp/interactions.js)",
|
|
41
|
+
"Bash(sed -n '283,295p' src/idp/interactions.js)",
|
|
42
|
+
"Bash(sed -n '600,610p' src/idp/interactions.js)",
|
|
43
|
+
"Bash(sed -n '638,650p' src/idp/interactions.js)",
|
|
44
|
+
"Bash(wait)",
|
|
45
|
+
"Bash(node --test --test-concurrency=1 test/schnorr-complete-defensive.test.js)",
|
|
46
|
+
"Bash(git commit -q -m 'review fixes \\(#539\\): stop leaking err.message + add regression tests *)",
|
|
47
|
+
"Bash(git commit -q -m 'review pass-3 \\(#539\\): log payload preserves stack + mock matches Node behaviour *)",
|
|
48
|
+
"Bash(git commit -q -m 'refactor\\(idp\\): sweep hijack-then-throw defensive pattern across all 5 interaction handlers \\(#526\\) *)",
|
|
49
|
+
"Bash(npm audit *)",
|
|
50
|
+
"Bash(node --check src/index.js)",
|
|
51
|
+
"Bash(node --check src/server.js)",
|
|
52
|
+
"Bash(node --test --test-concurrency=1 test/body-limit.test.js)",
|
|
53
|
+
"Bash(git commit -q -m 'feat: configurable bodyLimit via createServer / --body-limit / JSS_BODY_LIMIT \\(#474\\) *)",
|
|
54
|
+
"Bash(git commit -q -m 'review fixes \\(#543\\): unused imports + DATA_ROOT pollution + clearer comment *)",
|
|
55
|
+
"Bash(node --test --test-concurrency=1 test/ssrf.test.js)"
|
|
26
56
|
]
|
|
27
57
|
}
|
|
28
58
|
}
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/javascript-solid-server)
|
|
4
4
|
|
|
5
|
-
A minimal, fast, JSON-LD native Solid server.
|
|
5
|
+
A minimal, fast, JSON-LD native Solid server for the agentic web.
|
|
6
6
|
|
|
7
7
|
**[Documentation](https://javascriptsolidserver.github.io/docs/)** | **[GitHub](https://github.com/JavaScriptSolidServer/JavaScriptSolidServer)**
|
|
8
8
|
|
|
@@ -18,6 +18,7 @@ A minimal, fast, JSON-LD native Solid server.
|
|
|
18
18
|
- **JSON-LD Native** — Stores and serves JSON-LD by default, Turtle via `--conneg`
|
|
19
19
|
- **Web Access Control** — `.acl` file-based authorization
|
|
20
20
|
- **Solid-OIDC** — Built-in Identity Provider with DPoP, passkeys, Schnorr SSO
|
|
21
|
+
- **Programmatic Auth** — `POST /idp/credentials` issues tokens from email/password; agents and headless clients authenticate with no browser flow
|
|
21
22
|
- **WebSocket Notifications** — Real-time updates (solid-0.1 protocol)
|
|
22
23
|
- **Content Negotiation** — Turtle ↔ JSON-LD conversion (optional)
|
|
23
24
|
- **Multi-user Pods** — Path-based (`/alice/`) or subdomain-based (`alice.example.com`)
|
package/bin/jss.js
CHANGED
|
@@ -112,6 +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
116
|
.option('--nostr', 'Enable Nostr relay')
|
|
116
117
|
.option('--no-nostr', 'Disable Nostr relay')
|
|
117
118
|
.option('--nostr-path <path>', 'Nostr relay WebSocket path (default: /relay)')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "javascript-solid-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.207",
|
|
4
4
|
"description": "A minimal, fast Solid server",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,12 @@
|
|
|
52
52
|
"decentralized",
|
|
53
53
|
"activitypub",
|
|
54
54
|
"fediverse",
|
|
55
|
-
"nostr"
|
|
55
|
+
"nostr",
|
|
56
|
+
"json-ld",
|
|
57
|
+
"webid",
|
|
58
|
+
"mcp",
|
|
59
|
+
"agent",
|
|
60
|
+
"agentic"
|
|
56
61
|
],
|
|
57
62
|
"license": "AGPL-3.0-only",
|
|
58
63
|
"optionalDependencies": {
|
package/src/config.js
CHANGED
|
@@ -19,6 +19,12 @@ export const defaults = {
|
|
|
19
19
|
port: 4443,
|
|
20
20
|
host: '0.0.0.0',
|
|
21
21
|
root: './data',
|
|
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,
|
|
22
28
|
|
|
23
29
|
// SSL
|
|
24
30
|
sslKey: null,
|
|
@@ -167,6 +173,7 @@ const envMap = {
|
|
|
167
173
|
JSS_CORS_PROXY_MAX_BYTES: 'corsProxyMaxBytes',
|
|
168
174
|
JSS_CORS_PROXY_TIMEOUT_MS: 'corsProxyTimeoutMs',
|
|
169
175
|
JSS_CORS_PROXY_MAX_REDIRECTS: 'corsProxyMaxRedirects',
|
|
176
|
+
JSS_BODY_LIMIT: 'bodyLimit',
|
|
170
177
|
JSS_NOSTR: 'nostr',
|
|
171
178
|
JSS_NOSTR_PATH: 'nostrPath',
|
|
172
179
|
JSS_NOSTR_MAX_EVENTS: 'nostrMaxEvents',
|
|
@@ -278,8 +285,8 @@ function parseEnvValue(value, key) {
|
|
|
278
285
|
return parseInt(value, 10);
|
|
279
286
|
}
|
|
280
287
|
|
|
281
|
-
// Size values (quota)
|
|
282
|
-
if (key === 'defaultQuota') {
|
|
288
|
+
// Size values (quota, body limit)
|
|
289
|
+
if (key === 'defaultQuota' || key === 'bodyLimit') {
|
|
283
290
|
return parseSize(value);
|
|
284
291
|
}
|
|
285
292
|
|
package/src/handlers/git.js
CHANGED
|
@@ -167,16 +167,18 @@ function tryAutoInitRepo(repoAbs, log) {
|
|
|
167
167
|
|
|
168
168
|
// CORS headers for git responses. Single source of truth — used by the
|
|
169
169
|
// success path (Fastify reply on the OPTIONS preflight, raw stream on
|
|
170
|
-
// http-backend output)
|
|
171
|
-
//
|
|
172
|
-
//
|
|
170
|
+
// http-backend output), by every 4xx early-return in this module, and
|
|
171
|
+
// by the WAC preHandler's 401/402/403 returns in src/server.js (#548).
|
|
172
|
+
// Without these, browser-based git clients (e.g. jss.live/git/) see a
|
|
173
|
+
// generic CORS/network error instead of the actual status,
|
|
174
|
+
// undermining #371.
|
|
173
175
|
const GIT_CORS_HEADERS = {
|
|
174
176
|
'Access-Control-Allow-Origin': '*',
|
|
175
177
|
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
176
178
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Git-Protocol',
|
|
177
179
|
};
|
|
178
180
|
|
|
179
|
-
function setGitCorsHeaders(reply) {
|
|
181
|
+
export function setGitCorsHeaders(reply) {
|
|
180
182
|
for (const [k, v] of Object.entries(GIT_CORS_HEADERS)) {
|
|
181
183
|
reply.header(k, v);
|
|
182
184
|
}
|
package/src/handlers/resource.js
CHANGED
|
@@ -622,11 +622,163 @@ export async function handleGet(request, reply) {
|
|
|
622
622
|
return reply.send(content);
|
|
623
623
|
}
|
|
624
624
|
|
|
625
|
+
// Cap on how many bytes HEAD will FULLY read to decide a content type.
|
|
626
|
+
// GET reads the whole file regardless (it has to send the body anyway),
|
|
627
|
+
// but a HEAD on a multi-GB file must not slurp it into memory just to
|
|
628
|
+
// report a header. Above the cap, HEAD degrades gracefully per-case
|
|
629
|
+
// (see negotiateHeadFileContentType) instead of reading. Bounded
|
|
630
|
+
// first-bytes sniffs (HEAD_SNIFF_CHUNK_BYTES via a ranged read) are
|
|
631
|
+
// allowed at ANY size — they cost O(1).
|
|
632
|
+
const HEAD_FULL_READ_MAX_BYTES = 1024 * 1024;
|
|
633
|
+
const HEAD_SNIFF_CHUNK_BYTES = 1024;
|
|
634
|
+
|
|
635
|
+
// Read the first `bytes` of a file via a ranged stream — O(1) cost
|
|
636
|
+
// regardless of file size. Used by HEAD to run GET's "does it look
|
|
637
|
+
// like HTML?" sniffs without reading whole files.
|
|
638
|
+
function readFirstBytes(storagePath, bytes) {
|
|
639
|
+
return new Promise((resolve) => {
|
|
640
|
+
const result = storage.createReadStream(storagePath, { start: 0, end: bytes - 1 });
|
|
641
|
+
if (!result) return resolve(null);
|
|
642
|
+
const chunks = [];
|
|
643
|
+
result.stream.on('data', (c) => chunks.push(c));
|
|
644
|
+
result.stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
645
|
+
result.stream.on('error', () => resolve(null));
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Mirror handleGet's content-type decision for a FILE so HEAD emits the
|
|
651
|
+
* same Content-Type a GET with the same Accept header would (#552 —
|
|
652
|
+
* RFC 9110 §9.3.2: HEAD should send the same header fields as GET).
|
|
653
|
+
*
|
|
654
|
+
* GET's decision depends on file CONTENT in three places — the
|
|
655
|
+
* HTML-data-island sniff, the JSON-parse-success gate before conneg
|
|
656
|
+
* conversion, and the extensionless-file HTML sniff — so this may read
|
|
657
|
+
* the file, but only when the stored type makes content relevant and
|
|
658
|
+
* the file is within HEAD_FULL_READ_MAX_BYTES.
|
|
659
|
+
*
|
|
660
|
+
* Returns `{ contentType, converted }`. `converted: true` means GET
|
|
661
|
+
* would RE-SERIALIZE the body (Turtle conversion, or JSON-LD
|
|
662
|
+
* re-serialization through fromJsonLd) — its Content-Length would NOT
|
|
663
|
+
* be the on-disk size, so HEAD must omit Content-Length rather than
|
|
664
|
+
* claim stats.size for a body GET never sends. The extensionless HTML
|
|
665
|
+
* sniff only relabels the bytes (served as-is), so it is NOT a
|
|
666
|
+
* conversion.
|
|
667
|
+
*
|
|
668
|
+
* Large files (> HEAD_FULL_READ_MAX_BYTES) degrade per-case instead of
|
|
669
|
+
* being read in full:
|
|
670
|
+
* - RDF-stored: return the negotiated type WITHOUT the parse gate
|
|
671
|
+
* (optimistic). The gate only mirrors GET's corrupt-file fallback;
|
|
672
|
+
* a corrupt >1 MiB RDF document is far rarer than a valid one, so
|
|
673
|
+
* optimism keeps parity for the common case and confines the
|
|
674
|
+
* divergence to that corner.
|
|
675
|
+
* - HTML-looking content (any stored type) + Turtle-preferring
|
|
676
|
+
* Accept: stay at the stored type (conservative) — the data
|
|
677
|
+
* island can sit anywhere in the file, so its presence can't be
|
|
678
|
+
* checked without the full read this cap exists to avoid.
|
|
679
|
+
* - Extensionless: the HTML sniff only needs the first bytes, so it
|
|
680
|
+
* runs at ANY size via a bounded ranged read.
|
|
681
|
+
*
|
|
682
|
+
* Known residual divergences (deliberate, all need unusual documents):
|
|
683
|
+
* a parseable-but-unconvertible document (GET's fromJsonLd fails after
|
|
684
|
+
* JSON.parse succeeds → GET falls back to raw bytes), a corrupt
|
|
685
|
+
* >1 MiB RDF file (optimistic path above), and a >1 MiB HTML-looking
|
|
686
|
+
* file carrying a data island (conservative path above).
|
|
687
|
+
*/
|
|
688
|
+
async function negotiateHeadFileContentType({ storagePath, urlPath, stats, acceptHeader, connegEnabled }) {
|
|
689
|
+
const storedContentType = getContentType(storagePath);
|
|
690
|
+
const fitsFullRead = stats.size <= HEAD_FULL_READ_MAX_BYTES;
|
|
691
|
+
|
|
692
|
+
if (connegEnabled) {
|
|
693
|
+
// Same negotiation as handleGet's file branch (#325 q-aware).
|
|
694
|
+
const negotiated = selectContentType(acceptHeader, true);
|
|
695
|
+
const wantsTurtle = urlPath.endsWith('.ttl')
|
|
696
|
+
|| negotiated === RDF_TYPES.TURTLE
|
|
697
|
+
|| negotiated === RDF_TYPES.N3
|
|
698
|
+
|| negotiated === 'application/n-triples';
|
|
699
|
+
|
|
700
|
+
if (isRdfContentType(storedContentType)) {
|
|
701
|
+
const targetType = wantsTurtle ? 'text/turtle' : selectContentType(acceptHeader, connegEnabled);
|
|
702
|
+
if (!fitsFullRead) {
|
|
703
|
+
// Optimistic large-file path — see docstring.
|
|
704
|
+
return { contentType: targetType, converted: true };
|
|
705
|
+
}
|
|
706
|
+
const content = await storage.read(storagePath);
|
|
707
|
+
if (content !== null) {
|
|
708
|
+
try {
|
|
709
|
+
JSON.parse(content.toString()); // GET only converts when the body parses
|
|
710
|
+
return { contentType: targetType, converted: true };
|
|
711
|
+
} catch { /* not valid JSON-LD → GET serves as-is; fall through */ }
|
|
712
|
+
}
|
|
713
|
+
return { contentType: storedContentType, converted: false };
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// GET's data-island branch is gated on CONTENT ONLY — any file
|
|
717
|
+
// whose body starts with <!DOCTYPE/<html gets the island→Turtle
|
|
718
|
+
// conversion, regardless of stored type (.html, extensionless,
|
|
719
|
+
// .xhtml, …). Mirror that: a 1 KiB ranged sniff decides HTML-ness
|
|
720
|
+
// for O(1) cost on any file, and only HTML-looking content pays
|
|
721
|
+
// the full read for the island check.
|
|
722
|
+
if (wantsTurtle && fitsFullRead) {
|
|
723
|
+
const head = await readFirstBytes(storagePath, HEAD_SNIFF_CHUNK_BYTES);
|
|
724
|
+
const headTrimmed = head === null ? '' : head.trimStart();
|
|
725
|
+
let looksHtml = headTrimmed.startsWith('<!DOCTYPE') || headTrimmed.startsWith('<html');
|
|
726
|
+
let contentStr = null;
|
|
727
|
+
if (!looksHtml && head !== null && headTrimmed === '' && stats.size > HEAD_SNIFF_CHUNK_BYTES) {
|
|
728
|
+
// The chunk was entirely whitespace and the file continues past
|
|
729
|
+
// it — GET trims the FULL body, so the HTML marker may sit
|
|
730
|
+
// beyond the chunk. The file already fits the full-read budget;
|
|
731
|
+
// read it and decide exactly like GET does.
|
|
732
|
+
const content = await storage.read(storagePath);
|
|
733
|
+
if (content !== null) {
|
|
734
|
+
contentStr = content.toString();
|
|
735
|
+
const trimmed = contentStr.trimStart();
|
|
736
|
+
looksHtml = trimmed.startsWith('<!DOCTYPE') || trimmed.startsWith('<html');
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (looksHtml) {
|
|
740
|
+
// GET converts an HTML data island to Turtle only when the
|
|
741
|
+
// island exists AND its JSON parses; otherwise it serves the
|
|
742
|
+
// document as-is.
|
|
743
|
+
if (contentStr === null) {
|
|
744
|
+
const content = await storage.read(storagePath);
|
|
745
|
+
contentStr = content === null ? null : content.toString();
|
|
746
|
+
}
|
|
747
|
+
if (contentStr !== null) {
|
|
748
|
+
const jsonLdMatch = contentStr.match(/<script\s+type=["']application\/ld\+json["']\s*>([\s\S]*?)<\/script>/i);
|
|
749
|
+
if (jsonLdMatch) {
|
|
750
|
+
try {
|
|
751
|
+
JSON.parse(jsonLdMatch[1]);
|
|
752
|
+
return { contentType: 'text/turtle', converted: true };
|
|
753
|
+
} catch { /* unparseable island → GET serves as-is; fall through */ }
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
// No island conversion → fall through to the as-is path below
|
|
758
|
+
// (HTML-looking extensionless files still get the relabel sniff).
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// As-is path: GET sniffs extensionless files for HTML by content.
|
|
763
|
+
// Only the first bytes matter, so the sniff runs at any file size
|
|
764
|
+
// via a bounded ranged read. Relabel only — no conversion.
|
|
765
|
+
if (storedContentType === 'application/octet-stream') {
|
|
766
|
+
const head = await readFirstBytes(storagePath, HEAD_SNIFF_CHUNK_BYTES);
|
|
767
|
+
if (head !== null) {
|
|
768
|
+
const t = head.trimStart();
|
|
769
|
+
if (t.startsWith('<!DOCTYPE') || t.startsWith('<html')) {
|
|
770
|
+
return { contentType: 'text/html', converted: false };
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return { contentType: storedContentType, converted: false };
|
|
775
|
+
}
|
|
776
|
+
|
|
625
777
|
/**
|
|
626
778
|
* Handle HEAD request
|
|
627
779
|
*/
|
|
628
780
|
export async function handleHead(request, reply) {
|
|
629
|
-
const { storagePath, resourceUrl } = getRequestPaths(request);
|
|
781
|
+
const { urlPath, storagePath, resourceUrl } = getRequestPaths(request);
|
|
630
782
|
const stats = await storage.stat(storagePath);
|
|
631
783
|
|
|
632
784
|
if (!stats) {
|
|
@@ -687,7 +839,9 @@ export async function handleHead(request, reply) {
|
|
|
687
839
|
const { willServeMashlib, effectiveEtag } = getMashlibEtag(request, stats, storagePath);
|
|
688
840
|
headEtag = effectiveEtag;
|
|
689
841
|
isMashlibResponse = willServeMashlib;
|
|
690
|
-
contentType
|
|
842
|
+
// contentType for files is negotiated AFTER the If-None-Match check
|
|
843
|
+
// below — negotiation may read the file (#552), and GET 304s files
|
|
844
|
+
// before any read, so HEAD must not pay I/O a 304 will discard.
|
|
691
845
|
}
|
|
692
846
|
|
|
693
847
|
// Check If-None-Match using the final ETag (#456)
|
|
@@ -701,6 +855,26 @@ export async function handleHead(request, reply) {
|
|
|
701
855
|
}
|
|
702
856
|
}
|
|
703
857
|
|
|
858
|
+
let negotiationConverted = false;
|
|
859
|
+
if (!stats.isDirectory) {
|
|
860
|
+
// Mirror GET's content-type for files — including the negotiated
|
|
861
|
+
// Turtle/JSON-LD forms and the extensionless HTML sniff — so HEAD
|
|
862
|
+
// and GET agree (#552, RFC 9110 §9.3.2).
|
|
863
|
+
if (isMashlibResponse) {
|
|
864
|
+
contentType = 'text/html';
|
|
865
|
+
} else {
|
|
866
|
+
const negotiation = await negotiateHeadFileContentType({
|
|
867
|
+
storagePath,
|
|
868
|
+
urlPath,
|
|
869
|
+
stats,
|
|
870
|
+
acceptHeader: request.headers.accept || '',
|
|
871
|
+
connegEnabled,
|
|
872
|
+
});
|
|
873
|
+
contentType = negotiation.contentType;
|
|
874
|
+
negotiationConverted = negotiation.converted;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
704
878
|
const headers = getAllHeaders({
|
|
705
879
|
isContainer: stats.isDirectory,
|
|
706
880
|
etag: headEtag,
|
|
@@ -711,9 +885,19 @@ export async function handleHead(request, reply) {
|
|
|
711
885
|
mashlibEnabled: request.mashlibEnabled
|
|
712
886
|
});
|
|
713
887
|
|
|
888
|
+
// Mirror GET's Cache-Control for RDF responses (#552 header parity).
|
|
889
|
+
// GET applies RDF_CACHE_CONTROL uniformly wherever the response
|
|
890
|
+
// content type is RDF — container listings (Turtle/JSON-LD) and
|
|
891
|
+
// files (converted or as-is) alike; HTML responses don't get it.
|
|
892
|
+
if (isRdfContentType(contentType)) {
|
|
893
|
+
headers['Cache-Control'] = RDF_CACHE_CONTROL;
|
|
894
|
+
}
|
|
895
|
+
|
|
714
896
|
// Content-Length: only set when the file size matches the response body.
|
|
715
|
-
// Mashlib HTML and containers are dynamically generated
|
|
716
|
-
|
|
897
|
+
// Mashlib HTML and containers are dynamically generated, and a
|
|
898
|
+
// conneg-converted body (Turtle / re-serialized JSON-LD, #552) has a
|
|
899
|
+
// different length than the on-disk file — omit rather than lie.
|
|
900
|
+
if (!stats.isDirectory && !isMashlibResponse && !negotiationConverted) {
|
|
717
901
|
headers['Content-Length'] = stats.size;
|
|
718
902
|
}
|
|
719
903
|
|
package/src/idp/index.js
CHANGED
|
@@ -219,7 +219,11 @@ export async function idpPlugin(fastify, options) {
|
|
|
219
219
|
|
|
220
220
|
// /.well-known/openid-configuration
|
|
221
221
|
fastify.get('/.well-known/openid-configuration', async (request, reply) => {
|
|
222
|
-
// Ensure issuer has trailing slash for CTH compatibility
|
|
222
|
+
// Ensure issuer has trailing slash for CTH compatibility. Must stay
|
|
223
|
+
// in sync with createProvider's normalization (src/idp/provider.js)
|
|
224
|
+
// — the RFC 9207 `iss` authorization-response parameter and token
|
|
225
|
+
// `iss` claims come from the provider's issuer, and strict clients
|
|
226
|
+
// byte-compare them against this discovery field. See #524.
|
|
223
227
|
const normalizedIssuer = issuer.endsWith('/') ? issuer : issuer + '/';
|
|
224
228
|
// Base URL without trailing slash for building endpoint URLs
|
|
225
229
|
const baseUrl = issuer.endsWith('/') ? issuer.slice(0, -1) : issuer;
|
package/src/idp/interactions.js
CHANGED
|
@@ -14,6 +14,70 @@ import { expireSessionCookies } from './cookies.js';
|
|
|
14
14
|
// Security: Maximum body size for IdP form submissions (1MB)
|
|
15
15
|
const MAX_BODY_SIZE = 1024 * 1024;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Defensive wrapper around provider.interactionFinished for handlers
|
|
19
|
+
* that hijack the reply and let oidc-provider write the continuation
|
|
20
|
+
* redirect directly to the raw socket.
|
|
21
|
+
*
|
|
22
|
+
* The naive pattern is:
|
|
23
|
+
*
|
|
24
|
+
* reply.hijack();
|
|
25
|
+
* return provider.interactionFinished(request.raw, reply.raw, result, opts);
|
|
26
|
+
*
|
|
27
|
+
* If interactionFinished throws (most commonly `SessionNotFound` from
|
|
28
|
+
* oidc-provider's `#getInteraction` when the `_interaction` cookie is
|
|
29
|
+
* missing — URL pasted into a different browser, third-party cookies
|
|
30
|
+
* blocked, long idle past the cookie TTL), the hijacked reply can no
|
|
31
|
+
* longer be written by Fastify and the connection hangs until the
|
|
32
|
+
* gateway 504s. This helper turns that hang into a bounded 4xx instead.
|
|
33
|
+
*
|
|
34
|
+
* - SessionNotFound → 400 with a "session expired, please restart
|
|
35
|
+
* login from the beginning" page.
|
|
36
|
+
* - Anything else → 500 with a generic message. Raw err.message is
|
|
37
|
+
* never surfaced — adapter / provider error strings on an auth
|
|
38
|
+
* endpoint are a soft info-leak (mirrors handleSwitchAccount).
|
|
39
|
+
* - The full Error (including stack) is logged via request.log.warn
|
|
40
|
+
* under the `err` key so Pino serializes it properly.
|
|
41
|
+
*
|
|
42
|
+
* If interactionFinished managed a partial write before throwing
|
|
43
|
+
* (`reply.raw.headersSent === true`), the socket is past recovery —
|
|
44
|
+
* the error is re-thrown so the caller's outer catch logs it.
|
|
45
|
+
*
|
|
46
|
+
* Foundation work for #526. The auto-healing 303-to-retry behaviour
|
|
47
|
+
* that #526 ultimately wants can layer on top of this helper without
|
|
48
|
+
* touching the five call sites again.
|
|
49
|
+
*
|
|
50
|
+
* @param {object} request - Fastify request (uses .raw and .log)
|
|
51
|
+
* @param {object} reply - Fastify reply; will be hijacked
|
|
52
|
+
* @param {object} provider - oidc-provider instance
|
|
53
|
+
* @param {object} result - the interaction result to commit
|
|
54
|
+
* @param {object} opts - forwarded to interactionFinished
|
|
55
|
+
* (e.g. { mergeWithLastSubmission: true } for consent)
|
|
56
|
+
* @param {object} [logContext] - extra structured fields for the warn
|
|
57
|
+
* log on failure (e.g. { uid, accountId })
|
|
58
|
+
*/
|
|
59
|
+
async function finishInteractionDefensively(request, reply, provider, result, opts, logContext = {}) {
|
|
60
|
+
reply.hijack();
|
|
61
|
+
try {
|
|
62
|
+
await provider.interactionFinished(request.raw, reply.raw, result, opts);
|
|
63
|
+
return;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (reply.raw.headersSent) throw err;
|
|
66
|
+
// Spread logContext first so a caller-supplied `err` field can't
|
|
67
|
+
// clobber the real Error — Pino needs the actual Error under `err`
|
|
68
|
+
// to serialize name/message/stack/structured fields.
|
|
69
|
+
request.log.warn({ ...logContext, err }, 'interactionFinished failed after hijack');
|
|
70
|
+
const isSessionMissing = err.name === 'SessionNotFound';
|
|
71
|
+
const status = isSessionMissing ? 400 : 500;
|
|
72
|
+
const title = isSessionMissing ? 'Session expired' : 'Login error';
|
|
73
|
+
const message = isSessionMissing
|
|
74
|
+
? 'Your login session cookie is missing or expired. This usually means the link was opened in a different browser, third-party cookies are blocked, or too much time passed between steps. Please restart the login from the beginning.'
|
|
75
|
+
: 'Unexpected error completing login. Please try signing in again.';
|
|
76
|
+
reply.raw.writeHead(status, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
77
|
+
reply.raw.end(errorPage(title, message));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
17
81
|
/**
|
|
18
82
|
* Handle GET /idp/interaction/:uid
|
|
19
83
|
* Shows login or consent page based on interaction state
|
|
@@ -31,7 +95,7 @@ export async function handleInteractionGet(request, reply, provider) {
|
|
|
31
95
|
|
|
32
96
|
// If we need login
|
|
33
97
|
if (prompt.name === 'login') {
|
|
34
|
-
return reply.type('text/html').send(loginPage(uid, params.client_id, interaction.lastError));
|
|
98
|
+
return reply.type('text/html').send(loginPage(uid, params.client_id, interaction.lastSubmission?.lastError));
|
|
35
99
|
}
|
|
36
100
|
|
|
37
101
|
// If we need consent
|
|
@@ -109,9 +173,17 @@ export async function handleLogin(request, reply, provider) {
|
|
|
109
173
|
return reply.code(404).type('text/html').send(errorPage('Session expired', 'Please try logging in again.'));
|
|
110
174
|
}
|
|
111
175
|
|
|
112
|
-
// Validate input
|
|
176
|
+
// Validate input.
|
|
177
|
+
//
|
|
178
|
+
// The error must live inside `lastSubmission` — oidc-provider's
|
|
179
|
+
// Interaction.save() persists ONLY the fields in the model's
|
|
180
|
+
// IN_PAYLOAD list (lib/models/interaction.js), and `lastSubmission`
|
|
181
|
+
// is the designated slot for form re-render state. A bare
|
|
182
|
+
// `interaction.lastError = …` survives in memory but is silently
|
|
183
|
+
// DROPPED on save, so the redirected GET re-rendered the form with
|
|
184
|
+
// no error and users retried blind (#514).
|
|
113
185
|
if (!identifier || !password) {
|
|
114
|
-
interaction.
|
|
186
|
+
interaction.lastSubmission = { lastError: 'Username and password are required' };
|
|
115
187
|
await interaction.save(interaction.exp - Math.floor(Date.now() / 1000));
|
|
116
188
|
return reply.redirect(`/idp/interaction/${uid}`);
|
|
117
189
|
}
|
|
@@ -119,7 +191,8 @@ export async function handleLogin(request, reply, provider) {
|
|
|
119
191
|
// Authenticate
|
|
120
192
|
const account = await authenticate(identifier, password);
|
|
121
193
|
if (!account) {
|
|
122
|
-
|
|
194
|
+
// See the IN_PAYLOAD note above — must ride in lastSubmission.
|
|
195
|
+
interaction.lastSubmission = { lastError: 'Invalid username or password' };
|
|
123
196
|
await interaction.save(interaction.exp - Math.floor(Date.now() / 1000));
|
|
124
197
|
return reply.redirect(`/idp/interaction/${uid}`);
|
|
125
198
|
}
|
|
@@ -160,10 +233,11 @@ export async function handleLogin(request, reply, provider) {
|
|
|
160
233
|
interaction.result = result;
|
|
161
234
|
await interaction.save(interaction.exp - Math.floor(Date.now() / 1000));
|
|
162
235
|
|
|
163
|
-
// For browsers (mashlib, etc): do a proper HTTP redirect
|
|
236
|
+
// For browsers (mashlib, etc): do a proper HTTP redirect.
|
|
237
|
+
// Defensive wrapper guards against SessionNotFound / other throws
|
|
238
|
+
// after hijack — see finishInteractionDefensively at top of file.
|
|
164
239
|
if (wantsBrowserRedirect) {
|
|
165
|
-
reply
|
|
166
|
-
return provider.interactionFinished(request.raw, reply.raw, result, { mergeWithLastSubmission: false });
|
|
240
|
+
return finishInteractionDefensively(request, reply, provider, result, { mergeWithLastSubmission: false }, { uid });
|
|
167
241
|
}
|
|
168
242
|
|
|
169
243
|
// For CTH and programmatic clients: return JSON with location
|
|
@@ -282,16 +356,10 @@ export async function handleConsent(request, reply, provider) {
|
|
|
282
356
|
},
|
|
283
357
|
};
|
|
284
358
|
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return provider.interactionFinished(
|
|
290
|
-
request.raw,
|
|
291
|
-
reply.raw,
|
|
292
|
-
result,
|
|
293
|
-
{ mergeWithLastSubmission: true }
|
|
294
|
-
);
|
|
359
|
+
// Defensive wrapper guards against SessionNotFound / other throws
|
|
360
|
+
// after hijack — see finishInteractionDefensively at top of file.
|
|
361
|
+
// `mergeWithLastSubmission: true` is consent-specific.
|
|
362
|
+
return finishInteractionDefensively(request, reply, provider, result, { mergeWithLastSubmission: true }, { uid });
|
|
295
363
|
} catch (err) {
|
|
296
364
|
request.log.error(err, 'Consent error');
|
|
297
365
|
return reply.code(500).type('text/html').send(errorPage('Consent failed', err.message));
|
|
@@ -345,7 +413,7 @@ export async function handleSwitchAccount(request, reply, provider) {
|
|
|
345
413
|
interaction.session = undefined;
|
|
346
414
|
interaction.result = undefined;
|
|
347
415
|
interaction.prompt = { name: 'login', reasons: ['no_session'], details: {} };
|
|
348
|
-
interaction.
|
|
416
|
+
interaction.lastSubmission = undefined;
|
|
349
417
|
const ttl = Math.max(1, interaction.exp - Math.floor(Date.now() / 1000));
|
|
350
418
|
await interaction.save(ttl);
|
|
351
419
|
|
|
@@ -602,8 +670,8 @@ export async function handlePasskeyComplete(request, reply, provider) {
|
|
|
602
670
|
|
|
603
671
|
request.log.info({ accountId: account.id, uid }, 'Passkey login completed');
|
|
604
672
|
|
|
605
|
-
|
|
606
|
-
return
|
|
673
|
+
// Defensive wrapper — see finishInteractionDefensively at top of file.
|
|
674
|
+
return finishInteractionDefensively(request, reply, provider, result, { mergeWithLastSubmission: false }, { uid, accountId: account.id });
|
|
607
675
|
} catch (err) {
|
|
608
676
|
request.log.error(err, 'Passkey complete error');
|
|
609
677
|
return reply.code(500).type('text/html').send(errorPage('Error', err.message));
|
|
@@ -639,9 +707,9 @@ export async function handlePasskeySkip(request, reply, provider) {
|
|
|
639
707
|
|
|
640
708
|
request.log.info({ accountId: result.login.accountId, uid }, 'Passkey prompt skipped');
|
|
641
709
|
|
|
642
|
-
// Complete the OIDC interaction
|
|
643
|
-
|
|
644
|
-
return
|
|
710
|
+
// Complete the OIDC interaction. Defensive wrapper — see
|
|
711
|
+
// finishInteractionDefensively at top of file.
|
|
712
|
+
return finishInteractionDefensively(request, reply, provider, result, { mergeWithLastSubmission: false }, { uid, accountId: result.login.accountId });
|
|
645
713
|
} catch (err) {
|
|
646
714
|
request.log.error(err, 'Passkey skip error');
|
|
647
715
|
return reply.code(500).type('text/html').send(errorPage('Error', err.message));
|
|
@@ -819,8 +887,11 @@ export async function handleSchnorrComplete(request, reply, provider) {
|
|
|
819
887
|
|
|
820
888
|
request.log.info({ accountId: account.id, uid }, 'Schnorr login completed');
|
|
821
889
|
|
|
822
|
-
|
|
823
|
-
|
|
890
|
+
// Defensive wrapper — see finishInteractionDefensively at top of
|
|
891
|
+
// file. Originally inlined in #539 to fix #412 (the 504 hang on
|
|
892
|
+
// missing _interaction cookie); now shared with the four other
|
|
893
|
+
// hijack-then-throw sites in this module.
|
|
894
|
+
return finishInteractionDefensively(request, reply, provider, interaction.result, { mergeWithLastSubmission: false }, { uid, accountId: account.id });
|
|
824
895
|
} catch (err) {
|
|
825
896
|
request.log.error(err, 'Schnorr complete error');
|
|
826
897
|
return reply.code(500).type('text/html').send(errorPage('Error', err.message));
|
package/src/idp/provider.js
CHANGED
|
@@ -91,6 +91,17 @@ async function fetchClientDocument(clientId) {
|
|
|
91
91
|
* @returns {Promise<Provider>} - Configured oidc-provider instance
|
|
92
92
|
*/
|
|
93
93
|
export async function createProvider(issuer) {
|
|
94
|
+
// Normalize to the trailing-slash form — the SAME normalization the
|
|
95
|
+
// discovery handler applies to the `issuer` field of
|
|
96
|
+
// /.well-known/openid-configuration (src/idp/index.js, "Ensure
|
|
97
|
+
// issuer has trailing slash"). The provider's issuer feeds the
|
|
98
|
+
// RFC 9207 `iss` authorization-response parameter and the `iss`
|
|
99
|
+
// claim in issued tokens; RFC 9207 requires the param to be
|
|
100
|
+
// byte-identical to the advertised issuer, and strict clients
|
|
101
|
+
// (e.g. solid-oidc's handleRedirectFromLogin) reject the callback
|
|
102
|
+
// on mismatch — sign-in silently bounces before the token request
|
|
103
|
+
// ever fires. Keep the two normalizations in sync. See #524.
|
|
104
|
+
issuer = issuer.endsWith('/') ? issuer : issuer + '/';
|
|
94
105
|
const jwks = await getJwks();
|
|
95
106
|
const cookieKeys = await getCookieKeys();
|
|
96
107
|
|
package/src/idp/views.js
CHANGED
|
@@ -265,12 +265,26 @@ export function loginPage(uid, clientId, error = null, passkeyEnabled = true, sc
|
|
|
265
265
|
var INTERACTION_UID = '${safeUid}';
|
|
266
266
|
|
|
267
267
|
async function loginWithPasskey() {
|
|
268
|
+
// Passkeys require WebAuthn + a secure context. Stale Android
|
|
269
|
+
// System WebViews (common on de-Googled phones, #556) and plain
|
|
270
|
+
// http origins lack it. Detect up front and steer the user to the
|
|
271
|
+
// password form right below instead of failing deep in the
|
|
272
|
+
// ceremony with a cryptic error.
|
|
273
|
+
if (!window.isSecureContext || !window.PublicKeyCredential ||
|
|
274
|
+
!(navigator.credentials && navigator.credentials.get)) {
|
|
275
|
+
alert('Passkeys aren\\'t available in this browser. Please sign in with your username and password below.');
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
268
278
|
try {
|
|
269
|
-
// Get authentication options
|
|
279
|
+
// Get authentication options. No client-side correlation id is
|
|
280
|
+
// sent — the server mints the challengeKey (always-available
|
|
281
|
+
// Node crypto) and returns it; we echo options.challengeKey on
|
|
282
|
+
// verify. This deliberately avoids a browser crypto.randomUUID
|
|
283
|
+
// call that old WebViews lack (#556).
|
|
270
284
|
const optionsRes = await fetch('/idp/passkey/login/options', {
|
|
271
285
|
method: 'POST',
|
|
272
286
|
headers: { 'Content-Type': 'application/json' },
|
|
273
|
-
body: JSON.stringify({
|
|
287
|
+
body: JSON.stringify({})
|
|
274
288
|
});
|
|
275
289
|
const options = await optionsRes.json();
|
|
276
290
|
if (options.error) {
|
|
@@ -1032,6 +1046,15 @@ export function passkeyPromptPage(uid, accountId) {
|
|
|
1032
1046
|
var PASSKEY_ICON = '${passkeyIconEscaped}';
|
|
1033
1047
|
|
|
1034
1048
|
async function registerPasskey() {
|
|
1049
|
+
// Same WebAuthn / secure-context gate as the login page (#556):
|
|
1050
|
+
// on a stale WebView the create() ceremony would fail cryptically.
|
|
1051
|
+
// Steer to "Skip for now" instead of disabling the button on a
|
|
1052
|
+
// path that can't succeed.
|
|
1053
|
+
if (!window.isSecureContext || !window.PublicKeyCredential ||
|
|
1054
|
+
!(navigator.credentials && navigator.credentials.create)) {
|
|
1055
|
+
alert('Passkeys aren\\'t available in this browser. Tap "Skip for now" to continue.');
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1035
1058
|
const btn = document.getElementById('addBtn');
|
|
1036
1059
|
btn.disabled = true;
|
|
1037
1060
|
btn.textContent = 'Setting up...';
|