Refractoring Stage 5 DAV functions EDIT/DEL tied to creators account

This commit is contained in:
2026-10-16 17:15:20 +03:00
parent 0b52949f23
commit 88a8729f4f
6 changed files with 190 additions and 15 deletions
+6
View File
@@ -32,3 +32,9 @@ test('serializes contacts with escaped fields and an injected identifier', () =>
'N:Example Lovelace;Ada;;;\r\nEMAIL:ada@example.com\r\n' +
'NOTE:Research\\, analysis\\; mathematics\r\nEND:VCARD\r\n');
});
test('rejects DAV identifiers that can inject fields or escape resource paths', () => {
assert.throws(() => makeCalendarData({ date: '2026-10-16', title: 'Bad', _dav: { uid: 'good\r\nX-Evil: yes' } }), /identifier is invalid/);
assert.throws(() => makeCalendarData({ date: '2026-10-16', title: 'Bad', _dav: { uid: '../other' } }), /identifier is invalid/);
assert.throws(() => makeVcard({ name: 'Bad', email: 'x@example.test', _dav: { uid: 'x'.repeat(256) } }), /identifier is invalid/);
});
+66
View File
@@ -0,0 +1,66 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { assertDavObjectReference } = require('../desktop/dav/remote-reference.cjs');
const config = { id: 'dav-1', serverUrl: 'https://dav.example.test/' };
const collection = { url: 'https://dav.example.test/calendars/user/main/', displayName: 'Main' };
const object = { url: 'https://dav.example.test/calendars/user/main/event-1.ics', etag: '"v4"' };
const remote = {
accountId: 'dav-1',
collectionUrl: collection.url,
objectUrl: object.url,
etag: object.etag
};
test('accepts a resource verified against the configured server, collection, and current ETag', () => {
const result = assertDavObjectReference({ config, remote, collections: [collection], objects: [object] });
assert.equal(result.collection, collection);
assert.equal(result.object, object);
assert.equal(result.objectUrl, object.url);
});
test('accepts a relative server-returned object URL within its verified collection', () => {
const result = assertDavObjectReference({
config,
remote: { ...remote, objectUrl: 'event-1.ics' },
collections: [collection],
objects: [{ url: 'event-1.ics', etag: '"v4"' }]
});
assert.equal(result.objectUrl, object.url);
});
test('rejects account, collection, and resource references not returned by the server', () => {
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, accountId: 'other-account' }, collections: [collection], objects: [object]
}), /does not belong/);
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, collectionUrl: 'https://dav.example.test/other/' }, collections: [collection], objects: [object]
}), /collection is not available/);
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, objectUrl: 'https://dav.example.test/calendars/user/main/unknown.ics' }, collections: [collection], objects: [object]
}), /no longer available/);
});
test('rejects cross-origin, credential-bearing, query, traversal, and out-of-collection URLs', () => {
for (const objectUrl of [
'https://attacker.example/event.ics',
'https://user:pass@dav.example.test/calendars/user/main/event-1.ics',
'https://dav.example.test/calendars/user/main/event-1.ics?redirect=1',
'../other/event.ics',
'https://dav.example.test/calendars/user/main/',
'https://dav.example.test/calendars/user/other/event.ics'
]) {
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, objectUrl }, collections: [collection], objects: [object]
}));
}
});
test('rejects stale ETags and ETags with unexpected types', () => {
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, etag: '"v3"' }, collections: [collection], objects: [object]
}), /changed on the server/);
assert.throws(() => assertDavObjectReference({
config, remote: { ...remote, etag: 4 }, collections: [collection], objects: [{ ...object, etag: undefined }]
}), /version is invalid/);
});