diff --git a/packages/wekan-accounts-lockout/src/loginFailureDecision.js b/packages/wekan-accounts-lockout/src/loginFailureDecision.js index e7d48d2ffa..f52dfdadab 100644 --- a/packages/wekan-accounts-lockout/src/loginFailureDecision.js +++ b/packages/wekan-accounts-lockout/src/loginFailureDecision.js @@ -28,10 +28,23 @@ // every two-factor login; counting it would lock out legitimate 2FA users // after a few ordinary sign-ins. // +// 'password-login-disabled', 'forgot-password-disabled', +// 'ldap-password-login-disabled' — a policy refusal from server/authentication.js +// (models/lib/passwordLoginPolicy.js, server/lib/ldapPasswordLoginGuard.js), +// made whether or not the password was right. It tells a guesser nothing, so +// it is no guess to count - and counting it made this hook throw its own 403 +// "Incorrect password" over the policy's error, so the person was told the +// wrong thing and their account was locked by a setting. +// // A wrong second factor ('invalid-2fa-code') is intentionally NOT excluded: the // password was correct, so repeated wrong codes are a real guessing attempt and // should count. -const NON_FAILURE_ERROR_CODES = new Set(['no-2fa-code']); +const NON_FAILURE_ERROR_CODES = new Set([ + 'no-2fa-code', + 'password-login-disabled', + 'forgot-password-disabled', + 'ldap-password-login-disabled', +]); function isNonFailureError(error) { return ( diff --git a/server/autoArchiveCards.js b/server/autoArchiveCards.js index 67f1408f15..d14b94e325 100644 --- a/server/autoArchiveCards.js +++ b/server/autoArchiveCards.js @@ -46,7 +46,7 @@ export async function autoArchiveBoard(board, now = new Date()) { export async function scanAutoArchive(now = new Date()) { const boards = await Boards.find(AUTO_ARCHIVE_BOARD_SELECTOR, { - fields: { _id: 1, autoArchiveInactiveDays: 1, createdBy: 1 }, + fields: { _id: 1, autoArchiveInactiveDays: 1, members: 1 }, }).fetchAsync(); for (const board of boards) { // eslint-disable-next-line no-await-in-loop diff --git a/server/lib/attachmentContentIndex.js b/server/lib/attachmentContentIndex.js index c65ca79b66..2f604967fb 100644 --- a/server/lib/attachmentContentIndex.js +++ b/server/lib/attachmentContentIndex.js @@ -177,6 +177,16 @@ export async function indexNewAttachment(attachmentId) { if (!attachment) return; const meta = attachment.meta || {}; const ChangeHistory = require('/models/changeHistory').default; + // One "added" row per attachment. An upload already has one from + // server/models/changeHistoryHooks.js, and a durable rule copy one from its + // plan; a second row here showed the upload twice in the card history. The + // hash is on the attachment itself (contentHash), so nothing is lost. This + // row is written only for an attachment that has no "added" row - one the + // hook skips, such as an import. + if (require('/server/lib/syncRecordingScope').isSyncCopiedAttachment(attachmentId)) return; + const added = await ChangeHistory.rawCollection().findOne( + { entityType: 'attachment', entityId: attachmentId, changeType: 'added' }, { projection: { _id: 1 } }); + if (added) return; await ChangeHistory.record({ boardId: meta.boardId || null, swimlaneId: meta.swimlaneId || null, listId: meta.listId || null, cardId: meta.cardId || null, entityType: 'attachment', entityId: attachment._id, group: 'lifecycle', diff --git a/server/lib/syncRecordingScope.js b/server/lib/syncRecordingScope.js index 0e7dbc4dd0..5fb3320dee 100644 --- a/server/lib/syncRecordingScope.js +++ b/server/lib/syncRecordingScope.js @@ -79,6 +79,14 @@ function deferSyncChecklistRecording(kind, doc) { scope.kinds.delete(kind); return true; } +// Whether a durable rule copy names this attachment, active or not: its History +// row is the plan's, so the content index must not write another one +// (server/lib/attachmentContentIndex.js indexNewAttachment, deferred from the +// upload and so still inside this scope's async context). +function isSyncCopiedAttachment(attachmentId) { + const scope=storage.getStore(); + return !!scope && typeof attachmentId==='string' && scope.attachmentId===attachmentId; +} // The same one-shot slot for the one attachment a scope names. function deferSyncAttachmentRecording(kind, doc) { const scope=storage.getStore(); @@ -103,4 +111,4 @@ function deferSyncSwimlaneActivity(doc) { return true; } module.exports={withSyncRecordingDeferred,deferSyncRecording,deferSyncLabelActivities,deferSyncItemRecording,deferSyncChecklistRecording, - deferSyncAttachmentRecording,withSyncSwimlaneActivityDeferred,deferSyncSwimlaneActivity}; + deferSyncAttachmentRecording,isSyncCopiedAttachment,withSyncSwimlaneActivityDeferred,deferSyncSwimlaneActivity}; diff --git a/server/lib/tests/adminPanelAddresses.tests.js b/server/lib/tests/adminPanelAddresses.tests.js index 1cfe95f78b..2efc27c897 100644 --- a/server/lib/tests/adminPanelAddresses.tests.js +++ b/server/lib/tests/adminPanelAddresses.tests.js @@ -49,7 +49,8 @@ describe('Admin Panel allowed addresses', function () { const user = await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync(admin)); assert.equal(user.isAdmin, false); assert.equal(user.username, `apa-admin-${admin}`, 'still found: their boards work'); - assert.equal(await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })), null); + // Not found: Meteor 3's findOneAsync answers undefined, the driver null. + assert.equal(await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })) == null, true); const stored = await Meteor.users.findOneAsync(admin); assert.equal(stored.isAdmin, true, 'outside any caller the stored flag is read as it is'); }); diff --git a/tests/attachmentContent.test.cjs b/tests/attachmentContent.test.cjs index e59adbbf77..f8a418ed76 100644 --- a/tests/attachmentContent.test.cjs +++ b/tests/attachmentContent.test.cjs @@ -80,6 +80,10 @@ test('server: added -> hashed and indexed with an "added" history row; a whole r const index = read('server/lib/attachmentContentIndex.js'); assert.match(index, /changeType: 'added', previousContent: null,\s*newContent: \{ deleted: false, name: attachment\.name \|\| '', contentHash: result\.hash\.value \}/); assert.match(index, /group: 'lifecycle'/, 'a lifecycle row: its undo only ever soft-deletes or restores'); + // Only when it has none yet: the upload hook and a durable rule copy already + // wrote one, and a second "added" row listed the upload twice in History. + assert.match(index, /isSyncCopiedAttachment\(attachmentId\)\) return;/); + assert.match(index, /findOne\(\s*\{ entityType: 'attachment', entityId: attachmentId, changeType: 'added' \}[^;]*;\s*if \(added\) return;/); assert.match(index, /contentHash: \{ algorithm: lib\.ALGORITHM, value: actual\.value, size: actual\.size, at \}/, 'with the time it was made'); assert.match(index, /searchText,\s*generatedAt: at,/, 'the search text with the time it was made'); const server = read('server/routes/universalFileServer.js'); diff --git a/tests/boardActor.test.cjs b/tests/boardActor.test.cjs index 59cbb76f53..0ac191c783 100644 --- a/tests/boardActor.test.cjs +++ b/tests/boardActor.test.cjs @@ -56,3 +56,14 @@ test('a scheduled rule acts as the board, and its created card names its author' const create = helper.slice(helper.indexOf("if (action.actionType === 'createCard') {")); assert.match(create.slice(0, 1200), /const authorId = resolveActingUserId\(activity\);[\s\S]*\.\.\.\(authorId \? \{ userId: authorId \} : \{\}\),/); }); + +test('auto-archive fetches the members boardActorId decides from (negative: not createdBy)', () => { + // The scan projected { createdBy } only, so boardActorId saw no members and + // every auto-archive was recorded as nobody. + const src = read('server/autoArchiveCards.js'); + const scan = src.slice(src.indexOf('export async function scanAutoArchive')); + const fields = /fields:\s*\{([^}]*)\}/.exec(scan); + assert.ok(fields, 'scanAutoArchive projects its boards'); + assert.match(fields[1], /\bmembers:\s*1\b/); + assert.doesNotMatch(fields[1], /createdBy/); +}); diff --git a/tests/loginFailureDecision.test.cjs b/tests/loginFailureDecision.test.cjs index 02d593d596..15800583fa 100644 --- a/tests/loginFailureDecision.test.cjs +++ b/tests/loginFailureDecision.test.cjs @@ -158,6 +158,15 @@ test('unknown: non-password logins are ignored', () => { ); }); +test('known: a policy refusal is NOT a failure, and does not replace its error', () => { + for (const code of ['password-login-disabled', 'forgot-password-disabled', 'ldap-password-login-disabled']) { + assert.strictEqual(shouldProcessKnownUser({ type: 'password', user: { _id: 'u1' }, error: { error: code } }), false, code); + assert.strictEqual(isCountableFailure({ error: code }), false, code); + } + // Negative: an ordinary credential failure still counts. + assert.strictEqual(isCountableFailure({ error: 403, reason: AMBIGUOUS }), true); +}); + // --- Robustness ------------------------------------------------------------ test('never throws on missing / malformed loginInfo', () => {