Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(api): remove only reported and listed messages as evidence (#3747)

Hampus75b9aa359002
diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.json
index 391314503..dfabbc65b 100644
--- a/fluxer_admin/openapi-admin.json
+++ b/fluxer_admin/openapi-admin.json
@@ -8952,7 +8952,7 @@
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
}
},
- "description": "Suspend the account for duration_hours, or permanently with a duration of zero, and record the enforcement decision behind it. The decision is written first, then the suspension, then linked reports are resolved and the notice is sent. The X-Audit-Log-Reason header is required and becomes the first note. remove_evidence queues removal of the evidence messages after they are snapshotted. block_networks blocks addresses the account used in the last 30 days, for 90 days unless days says otherwise, and only with a permanent suspension. Exempt and special-purpose addresses, and addresses already blocked permanently or by another decision, are skipped and listed in skipped_ips. An address on which another account that is not suspended or closed was last active is refused with ENFORCEMENT_NETWORK_SHARED. Returns 409 when the account is closed. Requires USER_TEMP_BAN permission, plus MESSAGE_LOOKUP for evidence, REPORT_VIEW and REPORT_RESOLVE for reports, MESSAGE_SHRED for remove_evidence, and BAN_IP_ADD and USER_VIEW_IP for block_networks.",
+ "description": "Suspend the account for duration_hours, or permanently with a duration of zero, and record the enforcement decision behind it. The decision is written first, then the suspension, then linked reports are resolved and the notice is sent. The X-Audit-Log-Reason header is required and becomes the first note. remove_evidence queues removal of the reported messages and the evidence you listed after they are snapshotted, and keeps the other messages from the reports. block_networks blocks addresses the account used in the last 30 days, for 90 days unless days says otherwise, and only with a permanent suspension. Exempt and special-purpose addresses, and addresses already blocked permanently or by another decision, are skipped and listed in skipped_ips. An address on which another account that is not suspended or closed was last active is refused with ENFORCEMENT_NETWORK_SHARED. Returns 409 when the account is closed. Requires USER_TEMP_BAN permission, plus MESSAGE_LOOKUP for evidence, REPORT_VIEW and REPORT_RESOLVE for reports, MESSAGE_SHRED for remove_evidence, and BAN_IP_ADD and USER_VIEW_IP for block_networks.",
"security": [{"adminApiKey": []}],
"parameters": [
{
@@ -15369,7 +15369,7 @@
},
"basis": {"allOf": [{"$ref": "#/components/schemas/ModerationBasis"}]},
"remove_evidence": {
- "description": "Remove the evidence messages after they are snapshotted into the decision. Enforcement basis only",
+ "description": "Remove the reported messages and the evidence you listed after they are snapshotted into the decision. Other messages from the reports are kept. Enforcement basis only",
"type": "boolean"
},
"block_networks": {"allOf": [{"$ref": "#/components/schemas/NetworkBlockRequest"}]},
@@ -15440,7 +15440,7 @@
},
"decision": {"allOf": [{"$ref": "#/components/schemas/EnforcementDecisionInput"}]},
"remove_evidence": {
- "description": "Remove the evidence messages after they are snapshotted into the decision",
+ "description": "Remove the reported messages and the evidence you listed after they are snapshotted into the decision. Other messages from the reports are kept",
"type": "boolean"
},
"block_networks": {"allOf": [{"$ref": "#/components/schemas/NetworkBlockRequest"}]}
diff --git a/fluxer_api/src/api/admin/controllers/UserAdminController.ts b/fluxer_api/src/api/admin/controllers/UserAdminController.ts
index 6ae99f803..9f7c05233 100644
--- a/fluxer_api/src/api/admin/controllers/UserAdminController.ts
+++ b/fluxer_api/src/api/admin/controllers/UserAdminController.ts
@@ -1027,7 +1027,7 @@ export function UserAdminController(app: HonoApp) {
security: 'adminApiKey',
tags: 'Admin',
description:
- 'Suspend the account for duration_hours, or permanently with a duration of zero, and record the enforcement decision behind it. The decision is written first, then the suspension, then linked reports are resolved and the notice is sent. The X-Audit-Log-Reason header is required and becomes the first note. remove_evidence queues removal of the evidence messages after they are snapshotted. block_networks blocks addresses the account used in the last 30 days, for 90 days unless days says otherwise, and only with a permanent suspension. Exempt and special-purpose addresses, and addresses already blocked permanently or by another decision, are skipped and listed in skipped_ips. An address on which another account that is not suspended or closed was last active is refused with ENFORCEMENT_NETWORK_SHARED. Returns 409 when the account is closed. Requires USER_TEMP_BAN permission, plus MESSAGE_LOOKUP for evidence, REPORT_VIEW and REPORT_RESOLVE for reports, MESSAGE_SHRED for remove_evidence, and BAN_IP_ADD and USER_VIEW_IP for block_networks.',
+ 'Suspend the account for duration_hours, or permanently with a duration of zero, and record the enforcement decision behind it. The decision is written first, then the suspension, then linked reports are resolved and the notice is sent. The X-Audit-Log-Reason header is required and becomes the first note. remove_evidence queues removal of the reported messages and the evidence you listed after they are snapshotted, and keeps the other messages from the reports. block_networks blocks addresses the account used in the last 30 days, for 90 days unless days says otherwise, and only with a permanent suspension. Exempt and special-purpose addresses, and addresses already blocked permanently or by another decision, are skipped and listed in skipped_ips. An address on which another account that is not suspended or closed was last active is refused with ENFORCEMENT_NETWORK_SHARED. Returns 409 when the account is closed. Requires USER_TEMP_BAN permission, plus MESSAGE_LOOKUP for evidence, REPORT_VIEW and REPORT_RESOLVE for reports, MESSAGE_SHRED for remove_evidence, and BAN_IP_ADD and USER_VIEW_IP for block_networks.',
}),
async (ctx) => {
const {user_id: userId} = ctx.req.valid('param');
diff --git a/fluxer_api/src/api/enforcement/EnforcementDecisionService.ts b/fluxer_api/src/api/enforcement/EnforcementDecisionService.ts
index 6df1d7664..e0e77b711 100644
--- a/fluxer_api/src/api/enforcement/EnforcementDecisionService.ts
+++ b/fluxer_api/src/api/enforcement/EnforcementDecisionService.ts
@@ -249,8 +249,8 @@ function canBlockNetworks(kind: EnforcementKind, endsAt: Date | null | undefined
function reportOutcome(
report: IARSubmission,
- {kind, removal, removeEvidence}: RecordDecisionParams,
- evidence: ReadonlyArray<IARMessageContextRow>,
+ {kind, removal}: RecordDecisionParams,
+ removedEvidence: ReadonlyArray<IARMessageContextRow>,
): ReportItemOutcome | null {
if (kind === 'community_removal') {
return 'removed';
@@ -263,7 +263,7 @@ function reportOutcome(
const removed =
removal?.type === 'all_messages' ||
(removal?.type === 'messages' && removal.entries.some((entry) => entry.message_id === messageId)) ||
- (removeEvidence && evidence.some((message) => message.message_id === messageId));
+ removedEvidence.some((message) => message.message_id === messageId);
if (removed) {
return 'removed';
}
@@ -281,7 +281,8 @@ export class EnforcementDecisionService {
params: RecordDecisionParams,
applyState: (decisionId: bigint) => Promise<void>,
): Promise<RecordedDecision> {
- const {reports, evidence, removedMessageCount, internalNote, networkPlan} = await this.validate(params);
+ const {reports, evidence, removedEvidence, removedMessageCount, internalNote, networkPlan} =
+ await this.validate(params);
const {subject, kind, input, removal, profileReset, actor} = params;
const replacedDecisionId =
subject.type === 'user' && isAccountKind(kind) ? subject.user.enforcementDecisionId : null;
@@ -321,7 +322,7 @@ export class EnforcementDecisionService {
await this.clearReviewQueueFor(subject.user.id);
}
if (params.removeEvidence) {
- await this.queueEvidenceRemoval(decision, evidence, actor.adminUserId);
+ await this.queueEvidenceRemoval(decision, removedEvidence, actor.adminUserId);
}
const carried = replacedDecisionId
? await this.takeOverNetworkBlocks(replacedDecisionId, decision, {keep: canBlockNetworks(kind, params.endsAt)})
@@ -334,7 +335,7 @@ export class EnforcementDecisionService {
...networks.blocked,
];
await this.resolveReports(
- reports.map((report) => ({report, outcome: reportOutcome(report, params, evidence)})),
+ reports.map((report) => ({report, outcome: reportOutcome(report, params, removedEvidence)})),
actor,
internalNote,
);
@@ -830,6 +831,7 @@ export class EnforcementDecisionService {
}: RecordDecisionParams): Promise<{
reports: Array<IARSubmission>;
evidence: Array<IARMessageContextRow>;
+ removedEvidence: Array<IARMessageContextRow>;
removedMessageCount: number | null;
internalNote: string;
networkPlan: NetworkBlockPlan | null;
@@ -881,7 +883,12 @@ export class EnforcementDecisionService {
});
const removedIds = new Set(removed.map((entry) => entry.message_id));
const evidence = removed.length > 0 ? collected.filter((message) => removedIds.has(message.message_id)) : collected;
- if (removeEvidence && evidence.length === 0) {
+ const chosenIds = new Set([
+ ...explicitEvidence.map((entry) => entry.message_id),
+ ...reports.flatMap((report) => (report.reportedMessageId !== null ? [report.reportedMessageId] : [])),
+ ]);
+ const removedEvidence = removeEvidence ? evidence.filter((message) => chosenIds.has(message.message_id)) : [];
+ if (removeEvidence && removedEvidence.length === 0) {
throw InputValidationError.fromCode('remove_evidence', ValidationErrorCodes.ENFORCEMENT_EVIDENCE_REQUIRED);
}
if (reason.handling === 'restricted') {
@@ -909,9 +916,9 @@ export class EnforcementDecisionService {
if (removal?.type === 'messages') {
removedMessageCount = evidence.length + (await this.countOwnMessages(subject, removed.slice(snapshotted)));
} else if (removeEvidence) {
- removedMessageCount = evidence.length;
+ removedMessageCount = removedEvidence.length;
}
- return {reports, evidence, removedMessageCount, internalNote: actor.internalNote, networkPlan};
+ return {reports, evidence, removedEvidence, removedMessageCount, internalNote: actor.internalNote, networkPlan};
}
private async countOwnMessages(
diff --git a/fluxer_docs/src/content/docs/admin-api/users.mdx b/fluxer_docs/src/content/docs/admin-api/users.mdx
index bda8c4a1d..f56476674 100644
--- a/fluxer_docs/src/content/docs/admin-api/users.mdx
+++ b/fluxer_docs/src/content/docs/admin-api/users.mdx
@@ -940,7 +940,7 @@ Suspends the account for some hours or permanently, records the [enforcement dec
| --- | --- | --- |
| duration_hours | integer | How many hours to suspend for, or `0` for permanently (0-8760) |
| decision | [enforcement decision input](/admin-api/enforcement/#enforcement-decision-input) object | Why the account is suspended |
-| remove_evidence?<sup>1</sup> | boolean | Whether to delete the evidence messages after they are saved |
+| remove_evidence?<sup>1</sup> | boolean | Whether to delete the reported messages and the listed evidence once saved. Other report messages are kept |
| block_networks?<sup>2</sup> | [network block request](#network-block-request) object | The account's addresses to block |
<sup>1</sup> Needs `message:shred`
@@ -1097,7 +1097,7 @@ Closes the account, signs it out everywhere, schedules its deletion and returns
| days_until_deletion | integer | How many days until deletion, at least 14 (1-365) |
| basis | [basis](/admin-api/enforcement/#basis) object | Why the account is closed |
| replace_pending_deletion_at?<sup>1</sup> | ISO8601 timestamp | The `pending_deletion_at` of the schedule you replace |
-| remove_evidence?<sup>2</sup> | boolean | Whether to delete the evidence messages after they are saved |
+| remove_evidence?<sup>2</sup> | boolean | Whether to delete the reported messages and the listed evidence once saved. Other report messages are kept |
| block_networks?<sup>2</sup> | [network block request](#network-block-request) object | The account's addresses to block |
| immediate? | boolean | Whether to delete the account now |
diff --git a/packages/schema/src/domains/admin/AdminUserSchemas.ts b/packages/schema/src/domains/admin/AdminUserSchemas.ts
index 55f955198..412441feb 100644
--- a/packages/schema/src/domains/admin/AdminUserSchemas.ts
+++ b/packages/schema/src/domains/admin/AdminUserSchemas.ts
@@ -668,7 +668,7 @@ export const AdminUserDeletionScheduleRequest = z.object({
remove_evidence: z
.boolean()
.optional()
- .describe('Remove the evidence messages after they are snapshotted into the decision. Enforcement basis only'),
+ .describe('Remove the reported messages and the evidence you listed after they are snapshotted into the decision. Other messages from the reports are kept. Enforcement basis only'),
block_networks: NetworkBlockRequest.optional(),
immediate: z
.boolean()
diff --git a/packages/schema/src/domains/admin/EnforcementSchemas.ts b/packages/schema/src/domains/admin/EnforcementSchemas.ts
index beb059078..188d1795e 100644
--- a/packages/schema/src/domains/admin/EnforcementSchemas.ts
+++ b/packages/schema/src/domains/admin/EnforcementSchemas.ts
@@ -185,7 +185,7 @@ export const AdminUserBanRequest = z.object({
remove_evidence: z
.boolean()
.optional()
- .describe('Remove the evidence messages after they are snapshotted into the decision'),
+ .describe('Remove the reported messages and the evidence you listed after they are snapshotted into the decision. Other messages from the reports are kept'),
block_networks: NetworkBlockRequest.optional(),
});