javascript-solid-server 0.0.206 → 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/README.md +2 -1
- package/package.json +7 -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 +14 -5
- package/src/idp/provider.js +11 -0
- package/src/idp/views.js +25 -2
- package/src/server.js +10 -1
- package/src/tunnel/index.js +95 -10
- 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/tunnel.test.js +166 -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
|
+
});
|
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
|
});
|