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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Login-form error rendering (#514).
|
|
3
|
+
*
|
|
4
|
+
* Submitting the IdP sign-in form with bad credentials set
|
|
5
|
+
* `interaction.lastError` and redirected back to the form — but
|
|
6
|
+
* oidc-provider's Interaction.save() persists ONLY the fields in the
|
|
7
|
+
* model's IN_PAYLOAD list, and `lastError` isn't one of them. The
|
|
8
|
+
* property survived in memory, was silently dropped on save, and the
|
|
9
|
+
* redirected GET re-rendered a pristine form: no error banner, user
|
|
10
|
+
* retries blind (the "credibility cliff" in the issue).
|
|
11
|
+
*
|
|
12
|
+
* Fix: the message rides in `lastSubmission` — the IN_PAYLOAD slot
|
|
13
|
+
* oidc-provider designates for form re-render state.
|
|
14
|
+
*
|
|
15
|
+
* The test drives the real OIDC interaction flow over HTTP (register
|
|
16
|
+
* client → /idp/auth → interaction redirect → POST bad credentials →
|
|
17
|
+
* follow redirect) with manual cookie threading, and asserts the
|
|
18
|
+
* re-rendered form carries the error.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { describe, it, before, after } from 'node:test';
|
|
22
|
+
import assert from 'node:assert';
|
|
23
|
+
import { createServer } from '../src/server.js';
|
|
24
|
+
import { createServer as createNetServer } from 'net';
|
|
25
|
+
import fs from 'fs-extra';
|
|
26
|
+
|
|
27
|
+
const TEST_HOST = 'localhost';
|
|
28
|
+
const DATA_DIR = './test-data-idp-login-error';
|
|
29
|
+
|
|
30
|
+
function getAvailablePort() {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const srv = createNetServer();
|
|
33
|
+
srv.on('error', reject);
|
|
34
|
+
srv.listen(0, TEST_HOST, () => {
|
|
35
|
+
const port = srv.address().port;
|
|
36
|
+
srv.close(() => resolve(port));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Headers.getSetCookie() landed in Node 18.15 / 19.7. The engines
|
|
42
|
+
// field still declares >=18.0.0 (bump deferred — #541), so guard
|
|
43
|
+
// explicitly rather than collecting zero cookies and failing at a
|
|
44
|
+
// confusing distance. Skipping costs nothing on those runtimes: the
|
|
45
|
+
// IdP itself cannot run on Node 18 at all (oidc-provider uses
|
|
46
|
+
// Array#toReversed and crypto.hash — #523), so every IdP test is
|
|
47
|
+
// already broken there.
|
|
48
|
+
const HAS_GET_SET_COOKIE = typeof new Headers().getSetCookie === 'function';
|
|
49
|
+
|
|
50
|
+
// Collect cookies from a response and merge into a name→value jar.
|
|
51
|
+
function absorbCookies(jar, res) {
|
|
52
|
+
for (const c of res.headers.getSetCookie()) {
|
|
53
|
+
const [pair] = c.split(';');
|
|
54
|
+
const eq = pair.indexOf('=');
|
|
55
|
+
if (eq > 0) jar.set(pair.slice(0, eq).trim(), pair.slice(eq + 1).trim());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function cookieHeader(jar) {
|
|
59
|
+
return [...jar.entries()].map(([k, v]) => `${k}=${v}`).join('; ');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
describe('IdP login form error rendering (#514)', () => {
|
|
63
|
+
let server;
|
|
64
|
+
let baseUrl;
|
|
65
|
+
let originalDataRoot;
|
|
66
|
+
|
|
67
|
+
before(async () => {
|
|
68
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
69
|
+
await fs.remove(DATA_DIR);
|
|
70
|
+
await fs.ensureDir(DATA_DIR);
|
|
71
|
+
|
|
72
|
+
const port = await getAvailablePort();
|
|
73
|
+
baseUrl = `http://${TEST_HOST}:${port}`;
|
|
74
|
+
|
|
75
|
+
server = createServer({
|
|
76
|
+
logger: false,
|
|
77
|
+
root: DATA_DIR,
|
|
78
|
+
idp: true,
|
|
79
|
+
idpIssuer: baseUrl,
|
|
80
|
+
forceCloseConnections: true,
|
|
81
|
+
});
|
|
82
|
+
await server.listen({ port, host: TEST_HOST });
|
|
83
|
+
|
|
84
|
+
const res = await fetch(`${baseUrl}/.pods`, {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: { 'Content-Type': 'application/json' },
|
|
87
|
+
body: JSON.stringify({ name: 'alice', email: 'a@example.org', password: 'correct123' }),
|
|
88
|
+
});
|
|
89
|
+
assert.strictEqual(res.status, 201, 'prereq: pod creation');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
after(async () => {
|
|
93
|
+
if (server) await server.close();
|
|
94
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
95
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
96
|
+
await fs.remove(DATA_DIR);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('re-renders the form WITH the error after a failed login', async (t) => {
|
|
100
|
+
if (!HAS_GET_SET_COOKIE) {
|
|
101
|
+
t.skip('Headers.getSetCookie unavailable (Node <18.15) — IdP requires Node 20+ anyway, see #523/#541');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// 1. Dynamic client registration
|
|
105
|
+
const reg = await fetch(`${baseUrl}/idp/reg`, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: { 'Content-Type': 'application/json' },
|
|
108
|
+
body: JSON.stringify({
|
|
109
|
+
redirect_uris: [`${baseUrl}/cb`],
|
|
110
|
+
token_endpoint_auth_method: 'none',
|
|
111
|
+
grant_types: ['authorization_code'],
|
|
112
|
+
response_types: ['code'],
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
assert.strictEqual(reg.status, 201, 'client registration');
|
|
116
|
+
const { client_id: clientId } = await reg.json();
|
|
117
|
+
|
|
118
|
+
// 2. Start the auth flow → interaction redirect + session cookies
|
|
119
|
+
const jar = new Map();
|
|
120
|
+
const authUrl = `${baseUrl}/idp/auth?client_id=${encodeURIComponent(clientId)}` +
|
|
121
|
+
`&redirect_uri=${encodeURIComponent(`${baseUrl}/cb`)}` +
|
|
122
|
+
'&response_type=code&scope=openid+webid' +
|
|
123
|
+
'&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&state=s1';
|
|
124
|
+
const auth = await fetch(authUrl, { redirect: 'manual' });
|
|
125
|
+
absorbCookies(jar, auth);
|
|
126
|
+
const interactionPath = auth.headers.get('location');
|
|
127
|
+
assert.ok(interactionPath?.includes('/idp/interaction/'),
|
|
128
|
+
`expected interaction redirect, got ${interactionPath}`);
|
|
129
|
+
const interactionUrl = interactionPath.startsWith('http')
|
|
130
|
+
? interactionPath : `${baseUrl}${interactionPath}`;
|
|
131
|
+
|
|
132
|
+
// 3. Submit WRONG credentials
|
|
133
|
+
const post = await fetch(`${interactionUrl}/login`, {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
redirect: 'manual',
|
|
136
|
+
headers: {
|
|
137
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
138
|
+
Cookie: cookieHeader(jar),
|
|
139
|
+
},
|
|
140
|
+
body: 'username=alice&password=definitely-wrong',
|
|
141
|
+
});
|
|
142
|
+
absorbCookies(jar, post);
|
|
143
|
+
assert.ok([302, 303].includes(post.status),
|
|
144
|
+
`failed login must redirect back to the form, got ${post.status}`);
|
|
145
|
+
|
|
146
|
+
// 4. Follow the redirect — the re-rendered form must carry the error
|
|
147
|
+
const rerender = await fetch(interactionUrl, {
|
|
148
|
+
headers: { Cookie: cookieHeader(jar) },
|
|
149
|
+
});
|
|
150
|
+
assert.strictEqual(rerender.status, 200);
|
|
151
|
+
const html = await rerender.text();
|
|
152
|
+
assert.match(html, /<div class="error">Invalid username or password<\/div>/,
|
|
153
|
+
're-rendered form must show the auth error (#514: lastError was dropped by Interaction.save)');
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passkey login degrades on WebView/insecure contexts (#556).
|
|
3
|
+
*
|
|
4
|
+
* Two problems on stale Android System WebViews (de-Googled phones):
|
|
5
|
+
* 1. The login page's inline JS called `crypto.randomUUID()` to make a
|
|
6
|
+
* `visitorId` — missing on old WebViews (Chromium <92 / non-secure),
|
|
7
|
+
* so "Sign in with Passkey" threw `crypto.randomUUID is not a
|
|
8
|
+
* function`. Unlike jspod (#65), where the call lives inside the
|
|
9
|
+
* imported solid-oidc library, JSS OWNS the call site: the server
|
|
10
|
+
* already mints the challengeKey (Node crypto, always available)
|
|
11
|
+
* and returns it, so the browser call was redundant. Removed.
|
|
12
|
+
* 2. Both passkey ceremonies (login get(), prompt create()) would
|
|
13
|
+
* fail deep with a cryptic WebAuthn error on a WebView that can't
|
|
14
|
+
* do WebAuthn at all. Now guarded with a secure-context /
|
|
15
|
+
* PublicKeyCredential check that steers the user to the password
|
|
16
|
+
* form (login) or "Skip for now" (prompt).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, it, before, after } from 'node:test';
|
|
20
|
+
import assert from 'node:assert';
|
|
21
|
+
import { loginPage, passkeyPromptPage } from '../src/idp/views.js';
|
|
22
|
+
import { createServer } from '../src/server.js';
|
|
23
|
+
import { createServer as createNetServer } from 'net';
|
|
24
|
+
import fs from 'fs-extra';
|
|
25
|
+
|
|
26
|
+
const TEST_HOST = 'localhost';
|
|
27
|
+
const DATA_DIR = './test-data-passkey-degrade';
|
|
28
|
+
|
|
29
|
+
function getAvailablePort() {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const srv = createNetServer();
|
|
32
|
+
srv.on('error', reject);
|
|
33
|
+
srv.listen(0, TEST_HOST, () => {
|
|
34
|
+
const port = srv.address().port;
|
|
35
|
+
srv.close(() => resolve(port));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function inlineScripts(html) {
|
|
41
|
+
return [...html.matchAll(/<script>([\s\S]*?)<\/script>/g)].map((m) => m[1]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('passkey WebAuthn degradation (#556)', () => {
|
|
45
|
+
describe('rendered pages', () => {
|
|
46
|
+
it('login page no longer emits a browser crypto.randomUUID() call', () => {
|
|
47
|
+
const html = loginPage('uid-1', 'client-1', null, true, true);
|
|
48
|
+
assert.ok(!/crypto\.randomUUID\(\)/.test(html),
|
|
49
|
+
'no crypto.randomUUID() call should survive in the served JS');
|
|
50
|
+
assert.ok(html.includes('JSON.stringify({})'),
|
|
51
|
+
'login options request sends an empty body (server mints challengeKey)');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('login page guards on secure-context + WebAuthn before the ceremony', () => {
|
|
55
|
+
const html = loginPage('uid-1', 'client-1', null, true, true);
|
|
56
|
+
assert.ok(html.includes('isSecureContext') && html.includes('PublicKeyCredential'),
|
|
57
|
+
'WebAuthn availability is checked up front');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('passkey prompt page guards registration the same way', () => {
|
|
61
|
+
const html = passkeyPromptPage('uid-1', 'acct-1');
|
|
62
|
+
assert.ok(html.includes('isSecureContext') && html.includes('PublicKeyCredential'),
|
|
63
|
+
'registration ceremony is guarded too');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('every inline <script> in both pages is syntactically valid JS', () => {
|
|
67
|
+
for (const html of [loginPage('u', 'c', null, true, true), passkeyPromptPage('u', 'a')]) {
|
|
68
|
+
for (const src of inlineScripts(html)) {
|
|
69
|
+
assert.doesNotThrow(() => new Function(src),
|
|
70
|
+
'inline script must parse (escaping regression guard)');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('options endpoint mints the challengeKey server-side', () => {
|
|
77
|
+
let server;
|
|
78
|
+
let baseUrl;
|
|
79
|
+
let originalDataRoot;
|
|
80
|
+
|
|
81
|
+
before(async () => {
|
|
82
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
83
|
+
await fs.remove(DATA_DIR);
|
|
84
|
+
await fs.ensureDir(DATA_DIR);
|
|
85
|
+
const port = await getAvailablePort();
|
|
86
|
+
baseUrl = `http://${TEST_HOST}:${port}`;
|
|
87
|
+
server = createServer({
|
|
88
|
+
logger: false, root: DATA_DIR, idp: true,
|
|
89
|
+
idpIssuer: baseUrl, forceCloseConnections: true,
|
|
90
|
+
});
|
|
91
|
+
await server.listen({ port, host: TEST_HOST });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
after(async () => {
|
|
95
|
+
if (server) await server.close();
|
|
96
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
97
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
98
|
+
await fs.remove(DATA_DIR);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('returns a challengeKey for an EMPTY options body (no client visitorId needed)', async () => {
|
|
102
|
+
// This is what the page now sends. The server falls back to its
|
|
103
|
+
// own crypto.randomUUID() (Node, always available) and returns the
|
|
104
|
+
// key the client echoes on verify — so dropping the browser call
|
|
105
|
+
// is functionally complete, not a regression.
|
|
106
|
+
const res = await fetch(`${baseUrl}/idp/passkey/login/options`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: { 'Content-Type': 'application/json' },
|
|
109
|
+
body: JSON.stringify({}),
|
|
110
|
+
});
|
|
111
|
+
assert.strictEqual(res.status, 200, 'anonymous options request must succeed');
|
|
112
|
+
const body = await res.json();
|
|
113
|
+
assert.ok(typeof body.challengeKey === 'string' && body.challengeKey.length > 0,
|
|
114
|
+
'server must return a challengeKey the client can echo on verify');
|
|
115
|
+
assert.ok(body.challenge, 'WebAuthn challenge present');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for #412 — handleSchnorrComplete must not hang the
|
|
3
|
+
* connection (→ gateway 504) when `provider.interactionFinished` throws
|
|
4
|
+
* after `reply.hijack()`. The common trigger is `SessionNotFound` from
|
|
5
|
+
* oidc-provider's `#getInteraction` when the `_interaction` cookie is
|
|
6
|
+
* missing (cross-browser URL paste, third-party cookies blocked, long
|
|
7
|
+
* idle past the cookie TTL).
|
|
8
|
+
*
|
|
9
|
+
* Strategy: direct unit-test of the handler with a real account on a
|
|
10
|
+
* fixture DATA_ROOT (so `findById` returns a hit) plus a stub provider
|
|
11
|
+
* that throws SessionNotFound from `interactionFinished`. Captures the
|
|
12
|
+
* post-hijack write to `reply.raw` and asserts a bounded 400 response
|
|
13
|
+
* with the "session expired, restart login" page — instead of hanging.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, before, after } from 'node:test';
|
|
17
|
+
import assert from 'node:assert';
|
|
18
|
+
import fs from 'fs-extra';
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { handleSchnorrComplete } from '../src/idp/interactions.js';
|
|
21
|
+
import { createAccount } from '../src/idp/accounts.js';
|
|
22
|
+
|
|
23
|
+
const DATA_DIR = path.resolve('./test-data-schnorr-complete-defensive');
|
|
24
|
+
|
|
25
|
+
function makeFakeReplyAndCapture() {
|
|
26
|
+
let hijacked = false;
|
|
27
|
+
let status = null;
|
|
28
|
+
let headers = null;
|
|
29
|
+
const bodyChunks = [];
|
|
30
|
+
// Mirror Node's http.ServerResponse: `headersSent` flips to true the
|
|
31
|
+
// moment writeHead() commits the status line + headers to the socket,
|
|
32
|
+
// not only after end(). Modelling it any other way would let the
|
|
33
|
+
// `if (reply.raw.headersSent) throw err;` guard pass when it shouldn't.
|
|
34
|
+
let headersWritten = false;
|
|
35
|
+
return {
|
|
36
|
+
reply: {
|
|
37
|
+
hijack: () => { hijacked = true; },
|
|
38
|
+
code: () => { throw new Error('reply.code called after hijack — should not happen'); },
|
|
39
|
+
raw: {
|
|
40
|
+
get headersSent() { return headersWritten; },
|
|
41
|
+
writeHead: (s, h) => { status = s; headers = h; headersWritten = true; },
|
|
42
|
+
end: (body) => { headersWritten = true; if (body) bodyChunks.push(body); },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
captured: () => ({ hijacked, status, headers, body: bodyChunks.join('') }),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function makeFakeRequest({ uid, accountId }) {
|
|
50
|
+
const logs = [];
|
|
51
|
+
return {
|
|
52
|
+
params: { uid },
|
|
53
|
+
query: { accountId },
|
|
54
|
+
raw: {},
|
|
55
|
+
log: {
|
|
56
|
+
info: (...args) => logs.push(['info', args]),
|
|
57
|
+
warn: (...args) => logs.push(['warn', args]),
|
|
58
|
+
error: (...args) => logs.push(['error', args]),
|
|
59
|
+
},
|
|
60
|
+
_logs: logs,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('handleSchnorrComplete defensive recovery (#412)', () => {
|
|
65
|
+
let originalDataRoot;
|
|
66
|
+
let account;
|
|
67
|
+
|
|
68
|
+
before(async () => {
|
|
69
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
70
|
+
process.env.DATA_ROOT = DATA_DIR;
|
|
71
|
+
await fs.remove(DATA_DIR);
|
|
72
|
+
await fs.ensureDir(DATA_DIR);
|
|
73
|
+
account = await createAccount({
|
|
74
|
+
username: 'schnorrtest',
|
|
75
|
+
email: 'schnorr@example.org',
|
|
76
|
+
password: 'test12345',
|
|
77
|
+
webId: 'https://example.org/schnorrtest/profile/card#me',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
after(async () => {
|
|
82
|
+
await fs.remove(DATA_DIR);
|
|
83
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
84
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns 400 with a "session expired" page (not 504) when interactionFinished throws SessionNotFound', async () => {
|
|
88
|
+
const sessionErr = new Error('invalid_request — interaction session id cookie not found');
|
|
89
|
+
sessionErr.name = 'SessionNotFound';
|
|
90
|
+
|
|
91
|
+
const provider = {
|
|
92
|
+
Interaction: {
|
|
93
|
+
find: async () => ({
|
|
94
|
+
result: { login: { accountId: account.id } },
|
|
95
|
+
exp: Math.floor(Date.now() / 1000) + 600,
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
interactionFinished: async () => { throw sessionErr; },
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const { reply, captured } = makeFakeReplyAndCapture();
|
|
102
|
+
const request = makeFakeRequest({ uid: 'fake-uid', accountId: account.id });
|
|
103
|
+
|
|
104
|
+
await handleSchnorrComplete(request, reply, provider);
|
|
105
|
+
|
|
106
|
+
const c = captured();
|
|
107
|
+
assert.strictEqual(c.hijacked, true, 'must hijack before calling interactionFinished');
|
|
108
|
+
assert.strictEqual(c.status, 400, 'SessionNotFound must produce 400, not a hang');
|
|
109
|
+
assert.ok(c.headers && /text\/html/.test(c.headers['Content-Type']), 'response must be HTML');
|
|
110
|
+
assert.ok(/Session expired/.test(c.body), 'page title should be "Session expired"');
|
|
111
|
+
assert.ok(/restart the login/i.test(c.body), 'page should tell the user to restart');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('returns 500 with a generic message (no err.message leak) when interactionFinished throws an unknown error', async () => {
|
|
115
|
+
// Soft info-leak guard — mirrors handleSwitchAccount's pattern.
|
|
116
|
+
// The internal error message must NOT appear in the response body.
|
|
117
|
+
const internalErr = new Error('INTERNAL_DETAIL_xyz123_should_not_leak');
|
|
118
|
+
|
|
119
|
+
const provider = {
|
|
120
|
+
Interaction: {
|
|
121
|
+
find: async () => ({
|
|
122
|
+
result: { login: { accountId: account.id } },
|
|
123
|
+
exp: Math.floor(Date.now() / 1000) + 600,
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
interactionFinished: async () => { throw internalErr; },
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const { reply, captured } = makeFakeReplyAndCapture();
|
|
130
|
+
const request = makeFakeRequest({ uid: 'fake-uid', accountId: account.id });
|
|
131
|
+
|
|
132
|
+
await handleSchnorrComplete(request, reply, provider);
|
|
133
|
+
|
|
134
|
+
const c = captured();
|
|
135
|
+
assert.strictEqual(c.status, 500, 'unknown error must produce 500');
|
|
136
|
+
assert.ok(!/INTERNAL_DETAIL_xyz123_should_not_leak/.test(c.body),
|
|
137
|
+
'response body must not surface the raw err.message');
|
|
138
|
+
assert.ok(/Login error/.test(c.body), 'page title should be the generic "Login error"');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('completes successfully (no error response) when interactionFinished resolves', async () => {
|
|
142
|
+
let interactionFinishedCalled = false;
|
|
143
|
+
const provider = {
|
|
144
|
+
Interaction: {
|
|
145
|
+
find: async () => ({
|
|
146
|
+
result: { login: { accountId: account.id } },
|
|
147
|
+
exp: Math.floor(Date.now() / 1000) + 600,
|
|
148
|
+
}),
|
|
149
|
+
},
|
|
150
|
+
interactionFinished: async () => { interactionFinishedCalled = true; /* oidc-provider would write to reply.raw here */ },
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const { reply, captured } = makeFakeReplyAndCapture();
|
|
154
|
+
const request = makeFakeRequest({ uid: 'fake-uid', accountId: account.id });
|
|
155
|
+
|
|
156
|
+
await handleSchnorrComplete(request, reply, provider);
|
|
157
|
+
|
|
158
|
+
const c = captured();
|
|
159
|
+
assert.strictEqual(interactionFinishedCalled, true, 'interactionFinished must be called');
|
|
160
|
+
assert.strictEqual(c.hijacked, true, 'reply must be hijacked');
|
|
161
|
+
assert.strictEqual(c.status, null, 'no error response should be written when interactionFinished succeeds');
|
|
162
|
+
});
|
|
163
|
+
});
|
package/test/tunnel.test.js
CHANGED
|
@@ -199,4 +199,170 @@ describe('Tunnel Proxy', () => {
|
|
|
199
199
|
await new Promise(r => setTimeout(r, 50));
|
|
200
200
|
});
|
|
201
201
|
});
|
|
202
|
+
|
|
203
|
+
describe('Credential passthrough (#530)', () => {
|
|
204
|
+
// Register a tunnel, echo each request's received headers back in
|
|
205
|
+
// the response body, and attach the given response headers — lets
|
|
206
|
+
// tests assert both directions of the credential flow.
|
|
207
|
+
function echoTunnel(ws, name, { passthrough, responseHeaders = {} } = {}) {
|
|
208
|
+
ws.send(JSON.stringify({ type: 'register', name, ...(passthrough !== undefined && { passthrough }) }));
|
|
209
|
+
ws.on('message', (data) => {
|
|
210
|
+
const msg = JSON.parse(data.toString());
|
|
211
|
+
if (msg.type === 'request') {
|
|
212
|
+
ws.send(JSON.stringify({
|
|
213
|
+
type: 'response',
|
|
214
|
+
id: msg.id,
|
|
215
|
+
status: 200,
|
|
216
|
+
headers: { 'content-type': 'application/json', ...responseHeaders },
|
|
217
|
+
body: JSON.stringify({ receivedHeaders: msg.headers })
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return waitMsg(ws, 'registered');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
it('default registration strips credentials both ways (the security default)', async () => {
|
|
225
|
+
const ws = connectTunnel();
|
|
226
|
+
await new Promise(r => ws.on('open', r));
|
|
227
|
+
|
|
228
|
+
const ack = await echoTunnel(ws, 'noauth', {
|
|
229
|
+
responseHeaders: { 'set-cookie': 'leak=1; Path=/' }
|
|
230
|
+
});
|
|
231
|
+
assert.strictEqual(ack.passthrough, false,
|
|
232
|
+
'ack must state passthrough is off');
|
|
233
|
+
|
|
234
|
+
const res = await fetch(`${baseUrl}/tunnel/noauth/`, {
|
|
235
|
+
headers: { Cookie: 'session=secret', Authorization: 'Bearer visitor-token' }
|
|
236
|
+
});
|
|
237
|
+
assert.strictEqual(res.status, 200);
|
|
238
|
+
const { receivedHeaders } = await res.json();
|
|
239
|
+
assert.strictEqual(receivedHeaders.cookie, undefined,
|
|
240
|
+
'cookie must NOT reach the tunnel client by default');
|
|
241
|
+
assert.strictEqual(receivedHeaders.authorization, undefined,
|
|
242
|
+
'authorization must NOT reach the tunnel client by default');
|
|
243
|
+
// Feature-detect here too: on some undici versions get('set-cookie')
|
|
244
|
+
// is null even when Set-Cookie headers ARE present (only readable
|
|
245
|
+
// via getSetCookie), which would make a null assertion vacuous and
|
|
246
|
+
// could mask a regression in the default strip mode.
|
|
247
|
+
if (typeof res.headers.getSetCookie === 'function') {
|
|
248
|
+
assert.deepStrictEqual(res.headers.getSetCookie(), [],
|
|
249
|
+
'set-cookie from the tunnel client must NOT reach the visitor by default');
|
|
250
|
+
} else {
|
|
251
|
+
assert.strictEqual(res.headers.get('set-cookie'), null,
|
|
252
|
+
'set-cookie from the tunnel client must NOT reach the visitor by default');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
ws.close();
|
|
256
|
+
await new Promise(r => setTimeout(r, 50));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('passthrough registration forwards Cookie/Authorization in and Set-Cookie out', async () => {
|
|
260
|
+
const ws = connectTunnel();
|
|
261
|
+
await new Promise(r => ws.on('open', r));
|
|
262
|
+
|
|
263
|
+
const ack = await echoTunnel(ws, 'authapp', {
|
|
264
|
+
passthrough: true,
|
|
265
|
+
// Array value: JSON serialization preserves it and Fastify
|
|
266
|
+
// emits one Set-Cookie header per entry.
|
|
267
|
+
responseHeaders: { 'set-cookie': ['sess=abc; Path=/', 'csrf=xyz; Path=/'] }
|
|
268
|
+
});
|
|
269
|
+
assert.strictEqual(ack.passthrough, true, 'ack must confirm passthrough');
|
|
270
|
+
|
|
271
|
+
const res = await fetch(`${baseUrl}/tunnel/authapp/`, {
|
|
272
|
+
headers: { Cookie: 'session=secret', Authorization: 'Bearer visitor-token' }
|
|
273
|
+
});
|
|
274
|
+
assert.strictEqual(res.status, 200);
|
|
275
|
+
const { receivedHeaders } = await res.json();
|
|
276
|
+
assert.strictEqual(receivedHeaders.cookie, 'session=secret',
|
|
277
|
+
'cookie must reach the tunnel client with passthrough');
|
|
278
|
+
assert.strictEqual(receivedHeaders.authorization, 'Bearer visitor-token',
|
|
279
|
+
'authorization must reach the tunnel client with passthrough');
|
|
280
|
+
// Headers#getSetCookie() (Node ≥18.15) is the supported way to
|
|
281
|
+
// read multiple Set-Cookie values; get('set-cookie') behaviour
|
|
282
|
+
// varies by undici version and may expose only one value. Feature-
|
|
283
|
+
// detect: assert the full pair on the real API, degrade to a
|
|
284
|
+
// single-cookie assertion on older runtimes (engines floor bump
|
|
285
|
+
// tracked in #541).
|
|
286
|
+
const hasGetSetCookie = typeof res.headers.getSetCookie === 'function';
|
|
287
|
+
const setCookie = hasGetSetCookie
|
|
288
|
+
? res.headers.getSetCookie().join('; ')
|
|
289
|
+
: (res.headers.get('set-cookie') || '');
|
|
290
|
+
assert.ok(setCookie.includes('sess=abc'), `sess cookie must survive; got: ${setCookie}`);
|
|
291
|
+
if (hasGetSetCookie) {
|
|
292
|
+
assert.ok(setCookie.includes('csrf=xyz'), `csrf cookie must survive; got: ${setCookie}`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
ws.close();
|
|
296
|
+
await new Promise(r => setTimeout(r, 50));
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('passthrough strips the relay\'s own IdP cookies but keeps the service cookies (#530 session-hijack guard)', async () => {
|
|
300
|
+
const ws = connectTunnel();
|
|
301
|
+
await new Promise(r => ws.on('open', r));
|
|
302
|
+
|
|
303
|
+
await echoTunnel(ws, 'mixedcookies', { passthrough: true });
|
|
304
|
+
|
|
305
|
+
// Visitor carries BOTH a cookie for the tunnelled app AND the
|
|
306
|
+
// relay's own oidc session cookies (path=/, so a real browser
|
|
307
|
+
// would attach them on /tunnel/... too). The relay cookies must
|
|
308
|
+
// never reach the tunnel client; the app cookie must.
|
|
309
|
+
const res = await fetch(`${baseUrl}/tunnel/mixedcookies/`, {
|
|
310
|
+
headers: {
|
|
311
|
+
// `appsid` deliberately avoids the `_session` substring so the
|
|
312
|
+
// assertions below can test cookie *values* without collision.
|
|
313
|
+
Cookie: 'appsid=keep; _session=relay-secret; _session.sig=relay-sig; _interaction=flow',
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
assert.strictEqual(res.status, 200);
|
|
317
|
+
const { receivedHeaders } = await res.json();
|
|
318
|
+
const fwd = receivedHeaders.cookie || '';
|
|
319
|
+
assert.ok(fwd.includes('appsid=keep'),
|
|
320
|
+
`tunnelled-service cookie must survive; got: ${fwd}`);
|
|
321
|
+
assert.ok(!fwd.includes('relay-secret') && !fwd.includes('relay-sig'),
|
|
322
|
+
`relay _session cookies must NOT be forwarded; got: ${fwd}`);
|
|
323
|
+
assert.ok(!fwd.includes('_interaction'),
|
|
324
|
+
`relay _interaction cookies must NOT be forwarded; got: ${fwd}`);
|
|
325
|
+
|
|
326
|
+
ws.close();
|
|
327
|
+
await new Promise(r => setTimeout(r, 50));
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('passthrough never forwards Proxy-Authorization (relay-directed credential)', async () => {
|
|
331
|
+
const ws = connectTunnel();
|
|
332
|
+
await new Promise(r => ws.on('open', r));
|
|
333
|
+
|
|
334
|
+
await echoTunnel(ws, 'proxyauth', { passthrough: true });
|
|
335
|
+
|
|
336
|
+
const res = await fetch(`${baseUrl}/tunnel/proxyauth/`, {
|
|
337
|
+
headers: { 'Proxy-Authorization': 'Basic cmVsYXk6c2VjcmV0' }
|
|
338
|
+
});
|
|
339
|
+
assert.strictEqual(res.status, 200);
|
|
340
|
+
const { receivedHeaders } = await res.json();
|
|
341
|
+
assert.strictEqual(receivedHeaders['proxy-authorization'], undefined,
|
|
342
|
+
'proxy-authorization is addressed to the relay and must never be forwarded');
|
|
343
|
+
|
|
344
|
+
ws.close();
|
|
345
|
+
await new Promise(r => setTimeout(r, 50));
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('non-boolean passthrough values do not enable forwarding (strict === true)', async () => {
|
|
349
|
+
const ws = connectTunnel();
|
|
350
|
+
await new Promise(r => ws.on('open', r));
|
|
351
|
+
|
|
352
|
+
// "true" (string) must not opt a tunnel into credential forwarding.
|
|
353
|
+
const ack = await echoTunnel(ws, 'stringy', { passthrough: 'true' });
|
|
354
|
+
assert.strictEqual(ack.passthrough, false,
|
|
355
|
+
'string "true" must not enable passthrough');
|
|
356
|
+
|
|
357
|
+
const res = await fetch(`${baseUrl}/tunnel/stringy/`, {
|
|
358
|
+
headers: { Cookie: 'session=secret' }
|
|
359
|
+
});
|
|
360
|
+
const { receivedHeaders } = await res.json();
|
|
361
|
+
assert.strictEqual(receivedHeaders.cookie, undefined,
|
|
362
|
+
'credentials stay stripped for non-boolean opt-in values');
|
|
363
|
+
|
|
364
|
+
ws.close();
|
|
365
|
+
await new Promise(r => setTimeout(r, 50));
|
|
366
|
+
});
|
|
367
|
+
});
|
|
202
368
|
});
|
|
@@ -806,6 +806,69 @@ describe('profilePathCandidates — deployment-shape coverage (#411)', () => {
|
|
|
806
806
|
assert.deepStrictEqual(paths, [path.join(DATA_ROOT, 'profile', 'card.jsonld')]);
|
|
807
807
|
});
|
|
808
808
|
|
|
809
|
+
// Root-path WebIDs (#451): pathname `/` yields an empty pathnameRel,
|
|
810
|
+
// so the plain candidates resolve to directories (dataRoot itself /
|
|
811
|
+
// the pod dir) and the indexer ENOENT/not-a-regular-file'd every
|
|
812
|
+
// account shaped like `https://melvin.solid.social/#me`. The fix
|
|
813
|
+
// additionally probes the conventional `profile/card.jsonld`
|
|
814
|
+
// location under each directory candidate.
|
|
815
|
+
|
|
816
|
+
it('root-path WebID probes <dataRoot>/profile/card.jsonld (#451)', () => {
|
|
817
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://example.com/#me');
|
|
818
|
+
const expected = path.join(DATA_ROOT, 'profile', 'card.jsonld');
|
|
819
|
+
assert.ok(paths.includes(expected),
|
|
820
|
+
`expected ${expected}; got ${paths.join(', ')}`);
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
it('root-path WebID in subdomain mode probes <dataRoot>/<podName>/profile/card.jsonld (#451)', () => {
|
|
824
|
+
// The exact solid.social scenario from the issue: account `melvin`
|
|
825
|
+
// with WebID https://melvin.solid.social/#me, profile on disk at
|
|
826
|
+
// <dataRoot>/melvin/profile/card.jsonld.
|
|
827
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://melvin.solid.social/#me', 'melvin');
|
|
828
|
+
const expected = path.join(DATA_ROOT, 'melvin', 'profile', 'card.jsonld');
|
|
829
|
+
assert.ok(paths.includes(expected),
|
|
830
|
+
`expected ${expected}; got ${paths.join(', ')}`);
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('root-path WebID in subdomain mode does NOT probe the root pod profile (#451 cross-account guard)', () => {
|
|
834
|
+
// When the subdomain gate matches, <dataRoot>/profile/card.jsonld
|
|
835
|
+
// is the ROOT pod's document — a different account. A relative
|
|
836
|
+
// subject there ("@id": "#me") would absolutize against the
|
|
837
|
+
// probing account's WebID and pass the rebuild loop's @id check,
|
|
838
|
+
// binding the root pod's pubkeys to the subdomain account. The
|
|
839
|
+
// root-level fallback must therefore be suppressed when the gate
|
|
840
|
+
// matches.
|
|
841
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://melvin.solid.social/#me', 'melvin');
|
|
842
|
+
const rootPodProfile = path.join(DATA_ROOT, 'profile', 'card.jsonld');
|
|
843
|
+
assert.ok(!paths.includes(rootPodProfile),
|
|
844
|
+
`cross-account window: ${rootPodProfile} must not be probed for a subdomain account; got ${paths.join(', ')}`);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it('pod-root WebID with trailing slash probes <pod>/profile/card.jsonld (#451)', () => {
|
|
848
|
+
// Path-mode sibling of the root-path case: pathname `/alice/`
|
|
849
|
+
// also resolves to a directory without the fallback.
|
|
850
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://example.com/alice/#me');
|
|
851
|
+
const expected = path.join(DATA_ROOT, 'alice', 'profile', 'card.jsonld');
|
|
852
|
+
assert.ok(paths.includes(expected),
|
|
853
|
+
`expected ${expected}; got ${paths.join(', ')}`);
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
it('root-path WebID does NOT probe a podName dir when the host label does not match (#451)', () => {
|
|
857
|
+
// The subdomain gate must keep applying to the fallback candidate;
|
|
858
|
+
// otherwise a root-pod WebID could probe another account's pod dir.
|
|
859
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://melvin.solid.social/#me', 'other');
|
|
860
|
+
const leaked = path.join(DATA_ROOT, 'other', 'profile', 'card.jsonld');
|
|
861
|
+
assert.ok(!paths.includes(leaked),
|
|
862
|
+
`gate bypassed: ${leaked} should not be a candidate; got ${paths.join(', ')}`);
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
it('non-root WebIDs gain NO extra fallback candidates (#451)', () => {
|
|
866
|
+
// A document-shaped pathname must produce exactly the same
|
|
867
|
+
// candidate list as before the #451 fix.
|
|
868
|
+
const { paths } = profilePathCandidates(DATA_ROOT, 'https://example.com/alice/profile/card.jsonld#me');
|
|
869
|
+
assert.deepStrictEqual(paths, [path.join(DATA_ROOT, 'alice', 'profile', 'card.jsonld')]);
|
|
870
|
+
});
|
|
871
|
+
|
|
809
872
|
it('returns empty paths for an unparseable webId', () => {
|
|
810
873
|
assert.deepStrictEqual(profilePathCandidates(DATA_ROOT, 'not a url'), { paths: [], skipped: [] });
|
|
811
874
|
assert.deepStrictEqual(profilePathCandidates(DATA_ROOT, null), { paths: [], skipped: [] });
|