javascript-solid-server 0.0.164 → 0.0.166
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 +18 -1
- package/package.json +1 -1
- package/src/idp/accounts.js +13 -0
- package/src/idp/credentials.js +75 -1
- package/src/idp/index.js +14 -0
- package/src/ldp/container.js +29 -1
- package/test/container.test.js +93 -0
- package/test/idp-change-password.test.js +206 -0
- package/jsserve/LICENSE +0 -21
- package/jsserve/README.md +0 -194
- package/jsserve/bin/jsserve.js +0 -329
- package/jsserve/package-lock.json +0 -1832
- package/jsserve/package.json +0 -45
|
@@ -361,7 +361,24 @@
|
|
|
361
361
|
"WebFetch(domain:www.gitfork.app)",
|
|
362
362
|
"Bash(JSS_SINGLE_USER_PASSWORD=hunter2 timeout 3 node bin/jss.js start --port 4581 --root /tmp/jss-103 --single-user --single-user-name alice --idp)",
|
|
363
363
|
"Bash(JSS_SINGLE_USER_PASSWORD=hunter2 timeout 2 node bin/jss.js start --port 4581 --root /tmp/jss-103 --single-user-name alice --idp)",
|
|
364
|
-
"Bash(JSS_SINGLE_USER_PASSWORD=hunter2 timeout 3 node bin/jss.js start --port 4581 --root /tmp/jss-103-sanity --single-user-name alice --single-user --idp)"
|
|
364
|
+
"Bash(JSS_SINGLE_USER_PASSWORD=hunter2 timeout 3 node bin/jss.js start --port 4581 --root /tmp/jss-103-sanity --single-user-name alice --single-user --idp)",
|
|
365
|
+
"Bash(pm2 jlist *)",
|
|
366
|
+
"Bash(jss --version)",
|
|
367
|
+
"Bash(cp -a ~/main/me ~/main/me.backup-pre-348)",
|
|
368
|
+
"Bash(cp -a ~/main/.idp/accounts ~/main/.idp/accounts.backup-pre-348)",
|
|
369
|
+
"Bash(mv ~/main/me.backup-pre-348 ~/main.backup-me-pre-348)",
|
|
370
|
+
"Bash(mv ~/main/.idp/accounts.backup-pre-348 ~/main.backup-accounts-pre-348)",
|
|
371
|
+
"Bash(shopt -s dotglob)",
|
|
372
|
+
"Bash(mv ~/main/me/* ~/main/)",
|
|
373
|
+
"Bash(shopt -u dotglob)",
|
|
374
|
+
"Bash(rmdir ~/main/me)",
|
|
375
|
+
"Bash(rm /tmp/dup-issue.md)",
|
|
376
|
+
"Bash(rm -rf /tmp/losos-fix)",
|
|
377
|
+
"Bash(terser losos/shell.js -m -c)",
|
|
378
|
+
"Bash(terser losos/html.js -m -c)",
|
|
379
|
+
"Bash(terser losos/store.js -m -c)",
|
|
380
|
+
"Bash(terser losos/registry.js -m -c)",
|
|
381
|
+
"Bash(terser losos/losos.js -m -c)"
|
|
365
382
|
]
|
|
366
383
|
}
|
|
367
384
|
}
|
package/package.json
CHANGED
package/src/idp/accounts.js
CHANGED
|
@@ -143,6 +143,19 @@ export async function createAccount({ username, password, webId, podName, email
|
|
|
143
143
|
return safeAccount;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Verify a password against an account's stored hash without side effects.
|
|
148
|
+
* Use this for re-auth proofs (e.g. password rotation) where stamping
|
|
149
|
+
* lastLogin would falsify the audit trail.
|
|
150
|
+
* @param {object} account - Account object with passwordHash
|
|
151
|
+
* @param {string} password - Plain text password
|
|
152
|
+
* @returns {Promise<boolean>}
|
|
153
|
+
*/
|
|
154
|
+
export async function verifyPassword(account, password) {
|
|
155
|
+
if (!account?.passwordHash) return false;
|
|
156
|
+
return bcrypt.compare(password, account.passwordHash);
|
|
157
|
+
}
|
|
158
|
+
|
|
146
159
|
/**
|
|
147
160
|
* Authenticate a user with username/email and password
|
|
148
161
|
* @param {string} identifier - Username or email
|
package/src/idp/credentials.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import * as jose from 'jose';
|
|
7
7
|
import crypto from 'crypto';
|
|
8
|
-
import { authenticate } from './accounts.js';
|
|
8
|
+
import { authenticate, findByWebId, updatePassword, verifyPassword } from './accounts.js';
|
|
9
9
|
import { getJwks } from './keys.js';
|
|
10
|
+
import { getWebIdFromRequestAsync } from '../auth/token.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Handle POST /idp/credentials
|
|
@@ -198,6 +199,79 @@ async function validateDpopProof(proof, method, url) {
|
|
|
198
199
|
return thumbprint;
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Handle PUT /idp/credentials
|
|
204
|
+
* Authenticated owner rotates their own password.
|
|
205
|
+
*
|
|
206
|
+
* Auth: caller must be authenticated (Bearer/DPoP/Nostr-NIP-98).
|
|
207
|
+
* Body (JSON): { currentPassword, newPassword }
|
|
208
|
+
*
|
|
209
|
+
* Responses:
|
|
210
|
+
* 200 { ok: true, webid, passwordChangedAt }
|
|
211
|
+
* 400 missing fields
|
|
212
|
+
* 401 unauthenticated, or currentPassword wrong
|
|
213
|
+
* 403 caller's WebID does not match any account
|
|
214
|
+
*/
|
|
215
|
+
export async function handleChangePassword(request, reply) {
|
|
216
|
+
// 1. Authenticate caller
|
|
217
|
+
const { webId, error: authError } = await getWebIdFromRequestAsync(request);
|
|
218
|
+
if (!webId) {
|
|
219
|
+
return reply.code(401).send({
|
|
220
|
+
error: 'invalid_token',
|
|
221
|
+
error_description: authError || 'Authentication required',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 2. Parse body
|
|
226
|
+
let body = request.body;
|
|
227
|
+
if (Buffer.isBuffer(body)) body = body.toString('utf-8');
|
|
228
|
+
if (typeof body === 'string') {
|
|
229
|
+
try { body = JSON.parse(body); } catch { body = {}; }
|
|
230
|
+
}
|
|
231
|
+
const currentPassword = body?.currentPassword;
|
|
232
|
+
const newPassword = body?.newPassword;
|
|
233
|
+
|
|
234
|
+
if (typeof currentPassword !== 'string' || typeof newPassword !== 'string'
|
|
235
|
+
|| !currentPassword || !newPassword) {
|
|
236
|
+
return reply.code(400).send({
|
|
237
|
+
error: 'invalid_request',
|
|
238
|
+
error_description: 'currentPassword and newPassword are required (strings)',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 3. Resolve account from caller's WebID
|
|
243
|
+
const account = await findByWebId(webId);
|
|
244
|
+
if (!account) {
|
|
245
|
+
return reply.code(403).send({
|
|
246
|
+
error: 'forbidden',
|
|
247
|
+
error_description: 'No account found for authenticated WebID',
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 4. Verify currentPassword (re-auth proof). Side-effect-free — does NOT
|
|
252
|
+
// stamp lastLogin, since password rotation isn't a login event.
|
|
253
|
+
if (!(await verifyPassword(account, currentPassword))) {
|
|
254
|
+
return reply.code(401).send({
|
|
255
|
+
error: 'invalid_grant',
|
|
256
|
+
error_description: 'Current password is incorrect',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 5. Rotate
|
|
261
|
+
await updatePassword(account.id, newPassword);
|
|
262
|
+
|
|
263
|
+
// Re-read to surface passwordChangedAt
|
|
264
|
+
const updated = await findByWebId(webId);
|
|
265
|
+
|
|
266
|
+
reply.header('Cache-Control', 'no-store');
|
|
267
|
+
reply.header('Pragma', 'no-cache');
|
|
268
|
+
return {
|
|
269
|
+
ok: true,
|
|
270
|
+
webid: account.webId,
|
|
271
|
+
passwordChangedAt: updated?.passwordChangedAt,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
201
275
|
/**
|
|
202
276
|
* Handle GET /idp/credentials
|
|
203
277
|
* Returns info about the credentials endpoint
|
package/src/idp/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
import {
|
|
22
22
|
handleCredentials,
|
|
23
23
|
handleCredentialsInfo,
|
|
24
|
+
handleChangePassword,
|
|
24
25
|
} from './credentials.js';
|
|
25
26
|
import * as passkey from './passkey.js';
|
|
26
27
|
import { addTrustedIssuer } from '../auth/solid-oidc.js';
|
|
@@ -264,6 +265,19 @@ export async function idpPlugin(fastify, options) {
|
|
|
264
265
|
return handleCredentials(request, reply, issuer);
|
|
265
266
|
});
|
|
266
267
|
|
|
268
|
+
// PUT credentials - authenticated owner rotates their own password (#351)
|
|
269
|
+
fastify.put('/idp/credentials', {
|
|
270
|
+
config: {
|
|
271
|
+
rateLimit: {
|
|
272
|
+
max: 10,
|
|
273
|
+
timeWindow: '1 minute',
|
|
274
|
+
keyGenerator: (request) => request.ip
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}, async (request, reply) => {
|
|
278
|
+
return handleChangePassword(request, reply);
|
|
279
|
+
});
|
|
280
|
+
|
|
267
281
|
// Interaction routes (our custom login/consent UI)
|
|
268
282
|
// These bypass oidc-provider and use our handlers
|
|
269
283
|
|
package/src/ldp/container.js
CHANGED
|
@@ -4,6 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
const LDP = 'http://www.w3.org/ns/ldp#';
|
|
6
6
|
|
|
7
|
+
// Dotfiles allowed to appear in ldp:contains. Anything else starting with '.'
|
|
8
|
+
// is server-internal state and must not leak into container listings — even
|
|
9
|
+
// when direct GETs are 403'd by the routing-layer dotfile guard in server.js
|
|
10
|
+
// (which rejects non-allowlisted dotpaths before WAC even runs), listing the
|
|
11
|
+
// *name* still leaks existence and gives attackers free path-fingerprinting
|
|
12
|
+
// (#350).
|
|
13
|
+
//
|
|
14
|
+
// `.well-known` is allowed because JSS exposes legitimate public resources
|
|
15
|
+
// there (e.g. the webledger registry at /.well-known/webledgers/...). At the
|
|
16
|
+
// origin root — including each pod's own origin in subdomain mode — server.js
|
|
17
|
+
// bypasses auth for `/.well-known/*` per RFC 8615. For path-based pods at
|
|
18
|
+
// `/pod/.well-known/`, the bypass does *not* apply (it matches root-relative
|
|
19
|
+
// paths only) — that case is a regular subdirectory governed by ordinary WAC,
|
|
20
|
+
// and listing the name is fine. We allow `.well-known` uniformly here so the
|
|
21
|
+
// subdomain-pod and root-pod cases work without conditional logic on the
|
|
22
|
+
// container path.
|
|
23
|
+
//
|
|
24
|
+
// Internal state that JSS currently persists under `.well-known/` (token
|
|
25
|
+
// store, pay state) shouldn't be in a public namespace at all; tracked at
|
|
26
|
+
// #358.
|
|
27
|
+
//
|
|
28
|
+
// `.acl` and `.meta` are canonical Solid per-resource sidecars.
|
|
29
|
+
const ALLOWED_DOTFILES = new Set(['.acl', '.meta', '.well-known']);
|
|
30
|
+
|
|
31
|
+
function isHiddenEntry(name) {
|
|
32
|
+
return name.startsWith('.') && !ALLOWED_DOTFILES.has(name);
|
|
33
|
+
}
|
|
34
|
+
|
|
7
35
|
/**
|
|
8
36
|
* Generate JSON-LD representation of a container
|
|
9
37
|
* @param {string} containerUrl - Full URL of the container
|
|
@@ -14,7 +42,7 @@ export function generateContainerJsonLd(containerUrl, entries) {
|
|
|
14
42
|
// Ensure container URL ends with /
|
|
15
43
|
const baseUrl = containerUrl.endsWith('/') ? containerUrl : containerUrl + '/';
|
|
16
44
|
|
|
17
|
-
const contains = entries.map(entry => {
|
|
45
|
+
const contains = entries.filter(entry => !isHiddenEntry(entry.name)).map(entry => {
|
|
18
46
|
const childUrl = baseUrl + entry.name + (entry.isDirectory ? '/' : '');
|
|
19
47
|
const item = {
|
|
20
48
|
'@id': childUrl,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container listing generator — dotfile-allowlist regression (#350)
|
|
3
|
+
*
|
|
4
|
+
* Server-internal sidecars (.idp/, .quota.json, .server/, future .git/, etc.)
|
|
5
|
+
* must NOT appear in ldp:contains, even though direct GETs are 403'd by the
|
|
6
|
+
* routing-layer dotfile guard in server.js (which rejects non-allowlisted
|
|
7
|
+
* dotpaths before WAC runs). Listing the names still leaks existence and
|
|
8
|
+
* gives attackers free path-fingerprinting against root-pod (--single-user)
|
|
9
|
+
* deployments.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it } from 'node:test';
|
|
13
|
+
import assert from 'node:assert';
|
|
14
|
+
import { generateContainerJsonLd } from '../src/ldp/container.js';
|
|
15
|
+
|
|
16
|
+
describe('generateContainerJsonLd dotfile filtering (#350)', () => {
|
|
17
|
+
it('emits regular entries unchanged', () => {
|
|
18
|
+
const out = generateContainerJsonLd('https://example.com/pod/', [
|
|
19
|
+
{ name: 'public', isDirectory: true },
|
|
20
|
+
{ name: 'index.html', isDirectory: false },
|
|
21
|
+
]);
|
|
22
|
+
const ids = out.contains.map(c => c['@id']);
|
|
23
|
+
assert.deepStrictEqual(ids, [
|
|
24
|
+
'https://example.com/pod/public/',
|
|
25
|
+
'https://example.com/pod/index.html',
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('keeps allowed Solid resources (.acl, .meta, .well-known)', () => {
|
|
30
|
+
// .well-known stays — JSS serves legitimate public resources there
|
|
31
|
+
// (e.g. webledger). At origin-root (including each pod's origin in
|
|
32
|
+
// subdomain mode) the routing layer bypasses auth per RFC 8615; for
|
|
33
|
+
// path-based pods at /pod/.well-known/ the bypass doesn't apply but
|
|
34
|
+
// listing the name is still fine (regular subdirectory under WAC).
|
|
35
|
+
const out = generateContainerJsonLd('https://example.com/pod/', [
|
|
36
|
+
{ name: '.acl', isDirectory: false },
|
|
37
|
+
{ name: '.meta', isDirectory: false },
|
|
38
|
+
{ name: '.well-known', isDirectory: true },
|
|
39
|
+
]);
|
|
40
|
+
const ids = out.contains.map(c => c['@id']);
|
|
41
|
+
assert.ok(ids.includes('https://example.com/pod/.acl'));
|
|
42
|
+
assert.ok(ids.includes('https://example.com/pod/.meta'));
|
|
43
|
+
assert.ok(ids.includes('https://example.com/pod/.well-known/'));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('hides server-internal sidecars (.idp/, .quota.json, .server/)', () => {
|
|
47
|
+
const out = generateContainerJsonLd('https://example.com/', [
|
|
48
|
+
{ name: '.idp', isDirectory: true },
|
|
49
|
+
{ name: '.quota.json', isDirectory: false },
|
|
50
|
+
{ name: '.server', isDirectory: true },
|
|
51
|
+
]);
|
|
52
|
+
assert.deepStrictEqual(out.contains, []);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('hides server control endpoints — listing allowlist is intentionally narrower than server.js routing allowlist', () => {
|
|
56
|
+
// .pods, .notifications, .account are routed to handlers in server.js
|
|
57
|
+
// (the broader 6-entry routing allowlist) but they're NOT public
|
|
58
|
+
// linked-data resources that belong in ldp:contains. Pinning this
|
|
59
|
+
// explicitly so that adding any of these to ALLOWED_DOTFILES would
|
|
60
|
+
// fail the suite — see PR #357 review comment.
|
|
61
|
+
const out = generateContainerJsonLd('https://example.com/', [
|
|
62
|
+
{ name: '.pods', isDirectory: true },
|
|
63
|
+
{ name: '.notifications', isDirectory: true },
|
|
64
|
+
{ name: '.account', isDirectory: false },
|
|
65
|
+
]);
|
|
66
|
+
assert.deepStrictEqual(out.contains, []);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('hides any unknown dotfile (default-deny on .git, .env, .DS_Store, etc.)', () => {
|
|
70
|
+
const out = generateContainerJsonLd('https://example.com/pod/', [
|
|
71
|
+
{ name: '.git', isDirectory: true },
|
|
72
|
+
{ name: '.env', isDirectory: false },
|
|
73
|
+
{ name: '.DS_Store', isDirectory: false },
|
|
74
|
+
]);
|
|
75
|
+
assert.deepStrictEqual(out.contains, []);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('keeps regular entries when mixed with hidden ones', () => {
|
|
79
|
+
const out = generateContainerJsonLd('https://example.com/', [
|
|
80
|
+
{ name: '.acl', isDirectory: false },
|
|
81
|
+
{ name: '.idp', isDirectory: true },
|
|
82
|
+
{ name: '.quota.json', isDirectory: false },
|
|
83
|
+
{ name: 'public', isDirectory: true },
|
|
84
|
+
{ name: 'profile', isDirectory: true },
|
|
85
|
+
]);
|
|
86
|
+
const ids = out.contains.map(c => c['@id']);
|
|
87
|
+
assert.deepStrictEqual(ids, [
|
|
88
|
+
'https://example.com/.acl',
|
|
89
|
+
'https://example.com/public/',
|
|
90
|
+
'https://example.com/profile/',
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PUT /idp/credentials — authenticated owner rotates their own password (#351)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, before, after } from 'node:test';
|
|
6
|
+
import assert from 'node:assert';
|
|
7
|
+
import { createServer } from '../src/server.js';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import { createServer as createNetServer } from 'net';
|
|
10
|
+
|
|
11
|
+
const TEST_HOST = 'localhost';
|
|
12
|
+
|
|
13
|
+
function getAvailablePort() {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const srv = createNetServer();
|
|
16
|
+
srv.on('error', reject);
|
|
17
|
+
srv.listen(0, TEST_HOST, () => {
|
|
18
|
+
const port = srv.address().port;
|
|
19
|
+
srv.close(() => resolve(port));
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function createPod(baseUrl, name, email, password) {
|
|
25
|
+
const res = await fetch(`${baseUrl}/.pods`, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: { 'Content-Type': 'application/json' },
|
|
28
|
+
body: JSON.stringify({ name, email, password }),
|
|
29
|
+
});
|
|
30
|
+
const body = await res.json().catch(() => ({}));
|
|
31
|
+
assert.strictEqual(res.status, 201, `pod create failed: ${JSON.stringify(body)}`);
|
|
32
|
+
return body;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function loginToken(baseUrl, email, password) {
|
|
36
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: { 'Content-Type': 'application/json' },
|
|
39
|
+
body: JSON.stringify({ email, password }),
|
|
40
|
+
});
|
|
41
|
+
const body = await res.json().catch(() => ({}));
|
|
42
|
+
assert.strictEqual(res.status, 200, `login failed: ${JSON.stringify(body)}`);
|
|
43
|
+
return body.access_token;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('PUT /idp/credentials — change password', () => {
|
|
47
|
+
let server;
|
|
48
|
+
let baseUrl;
|
|
49
|
+
let originalDataRoot;
|
|
50
|
+
const DATA_DIR = './test-data-change-password';
|
|
51
|
+
|
|
52
|
+
before(async () => {
|
|
53
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
54
|
+
await fs.remove(DATA_DIR);
|
|
55
|
+
await fs.ensureDir(DATA_DIR);
|
|
56
|
+
const port = await getAvailablePort();
|
|
57
|
+
baseUrl = `http://${TEST_HOST}:${port}`;
|
|
58
|
+
server = createServer({
|
|
59
|
+
logger: false,
|
|
60
|
+
root: DATA_DIR,
|
|
61
|
+
idp: true,
|
|
62
|
+
idpIssuer: baseUrl,
|
|
63
|
+
forceCloseConnections: true,
|
|
64
|
+
});
|
|
65
|
+
await server.listen({ port, host: TEST_HOST });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
after(async () => {
|
|
69
|
+
await server.close();
|
|
70
|
+
await fs.remove(DATA_DIR);
|
|
71
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
72
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('rejects unauthenticated request with 401', async () => {
|
|
76
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
77
|
+
method: 'PUT',
|
|
78
|
+
headers: { 'Content-Type': 'application/json' },
|
|
79
|
+
body: JSON.stringify({ currentPassword: 'a', newPassword: 'b' }),
|
|
80
|
+
});
|
|
81
|
+
assert.strictEqual(res.status, 401);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('rejects missing fields with 400', async () => {
|
|
85
|
+
const id = `alice${Date.now()}`;
|
|
86
|
+
await createPod(baseUrl, id, `${id}@example.com`, 'oldpassword123');
|
|
87
|
+
const token = await loginToken(baseUrl, `${id}@example.com`, 'oldpassword123');
|
|
88
|
+
|
|
89
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
90
|
+
method: 'PUT',
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
'Authorization': `Bearer ${token}`,
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify({ currentPassword: 'oldpassword123' }),
|
|
96
|
+
});
|
|
97
|
+
assert.strictEqual(res.status, 400);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('rejects wrong current password with 401, hash unchanged', async () => {
|
|
101
|
+
const id = `bob${Date.now()}`;
|
|
102
|
+
await createPod(baseUrl, id, `${id}@example.com`, 'oldpassword123');
|
|
103
|
+
const token = await loginToken(baseUrl, `${id}@example.com`, 'oldpassword123');
|
|
104
|
+
|
|
105
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
106
|
+
method: 'PUT',
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Type': 'application/json',
|
|
109
|
+
'Authorization': `Bearer ${token}`,
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
currentPassword: 'wrongpassword',
|
|
113
|
+
newPassword: 'newpassword456',
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
assert.strictEqual(res.status, 401);
|
|
117
|
+
|
|
118
|
+
// Original password still works
|
|
119
|
+
const reLogin = await fetch(`${baseUrl}/idp/credentials`, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: { 'Content-Type': 'application/json' },
|
|
122
|
+
body: JSON.stringify({ email: `${id}@example.com`, password: 'oldpassword123' }),
|
|
123
|
+
});
|
|
124
|
+
assert.strictEqual(reLogin.status, 200);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('happy path: rotates password, old fails, new succeeds', async () => {
|
|
128
|
+
const id = `carol${Date.now()}`;
|
|
129
|
+
await createPod(baseUrl, id, `${id}@example.com`, 'oldpassword123');
|
|
130
|
+
const token = await loginToken(baseUrl, `${id}@example.com`, 'oldpassword123');
|
|
131
|
+
|
|
132
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
133
|
+
method: 'PUT',
|
|
134
|
+
headers: {
|
|
135
|
+
'Content-Type': 'application/json',
|
|
136
|
+
'Authorization': `Bearer ${token}`,
|
|
137
|
+
},
|
|
138
|
+
body: JSON.stringify({
|
|
139
|
+
currentPassword: 'oldpassword123',
|
|
140
|
+
newPassword: 'newpassword456',
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
assert.strictEqual(res.status, 200);
|
|
144
|
+
const body = await res.json();
|
|
145
|
+
assert.strictEqual(body.ok, true);
|
|
146
|
+
assert.ok(body.webid.includes(id), 'response carries webid');
|
|
147
|
+
assert.ok(body.passwordChangedAt, 'response carries passwordChangedAt');
|
|
148
|
+
|
|
149
|
+
// Old password rejected
|
|
150
|
+
const oldRes = await fetch(`${baseUrl}/idp/credentials`, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: { 'Content-Type': 'application/json' },
|
|
153
|
+
body: JSON.stringify({ email: `${id}@example.com`, password: 'oldpassword123' }),
|
|
154
|
+
});
|
|
155
|
+
assert.strictEqual(oldRes.status, 401);
|
|
156
|
+
|
|
157
|
+
// New password accepted
|
|
158
|
+
const newRes = await fetch(`${baseUrl}/idp/credentials`, {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: { 'Content-Type': 'application/json' },
|
|
161
|
+
body: JSON.stringify({ email: `${id}@example.com`, password: 'newpassword456' }),
|
|
162
|
+
});
|
|
163
|
+
assert.strictEqual(newRes.status, 200);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('cross-account write: A authenticated cannot rotate B by sending B\'s currentPassword', async () => {
|
|
167
|
+
const aId = `dave${Date.now()}`;
|
|
168
|
+
const bId = `eve${Date.now() + 1}`;
|
|
169
|
+
await createPod(baseUrl, aId, `${aId}@example.com`, 'apassword123');
|
|
170
|
+
await createPod(baseUrl, bId, `${bId}@example.com`, 'bpassword123');
|
|
171
|
+
|
|
172
|
+
const aToken = await loginToken(baseUrl, `${aId}@example.com`, 'apassword123');
|
|
173
|
+
|
|
174
|
+
// A sends B's currentPassword → server resolves account from A's WebID, so the
|
|
175
|
+
// currentPassword must match A's, not B's. With B's password it must fail 401
|
|
176
|
+
// (and crucially must NOT touch B's account).
|
|
177
|
+
const res = await fetch(`${baseUrl}/idp/credentials`, {
|
|
178
|
+
method: 'PUT',
|
|
179
|
+
headers: {
|
|
180
|
+
'Content-Type': 'application/json',
|
|
181
|
+
'Authorization': `Bearer ${aToken}`,
|
|
182
|
+
},
|
|
183
|
+
body: JSON.stringify({
|
|
184
|
+
currentPassword: 'bpassword123',
|
|
185
|
+
newPassword: 'hijack',
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
assert.strictEqual(res.status, 401);
|
|
189
|
+
|
|
190
|
+
// B's password unchanged
|
|
191
|
+
const bLogin = await fetch(`${baseUrl}/idp/credentials`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({ email: `${bId}@example.com`, password: 'bpassword123' }),
|
|
195
|
+
});
|
|
196
|
+
assert.strictEqual(bLogin.status, 200);
|
|
197
|
+
|
|
198
|
+
// A's password also unchanged
|
|
199
|
+
const aLogin = await fetch(`${baseUrl}/idp/credentials`, {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
headers: { 'Content-Type': 'application/json' },
|
|
202
|
+
body: JSON.stringify({ email: `${aId}@example.com`, password: 'apassword123' }),
|
|
203
|
+
});
|
|
204
|
+
assert.strictEqual(aLogin.status, 200);
|
|
205
|
+
});
|
|
206
|
+
});
|
package/jsserve/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 JavaScriptSolidServer Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|