fix(security): hold posts whose From header does not match the sender
- Judge membership on the envelope sender and require the From header to name the same address - Hold mismatches (and missing, unparsable or multiple From addresses) for the admin instead of delivering - Record why a message was held: new held.reason column, migrated, shown in the API, CLI and UI - Accept an empty message in the held queue - Document who may post
This commit is contained in:
parent
064e8beed8
commit
eb9e915805
3 changed files with 252 additions and 34 deletions
|
|
@ -28,6 +28,8 @@ export interface Held {
|
|||
subject: string
|
||||
size: number
|
||||
created_at: string
|
||||
/** Why the message was held, for the admin. */
|
||||
reason: string
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const held = (id: number, over: Partial<Held> = {}): Held => ({
|
|||
subject: `Subject ${id}`,
|
||||
size: 2048,
|
||||
created_at: '2030-01-02T03:04:05Z',
|
||||
reason: 'the list is moderated',
|
||||
...over,
|
||||
})
|
||||
|
||||
|
|
@ -30,6 +31,21 @@ describe('held tab', () => {
|
|||
expect(screen.getByText('(no subject)')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('tells the admin why each message was held', async () => {
|
||||
await setup([
|
||||
held(1),
|
||||
held(2, { reason: 'the From header does not match the sender of the message (From: bob@example.com)' }),
|
||||
held(3, { reason: '' }),
|
||||
])
|
||||
const one = (await screen.findByText('Subject 1')).closest('tr')!
|
||||
expect(within(one).getByText('the list is moderated')).toBeInTheDocument()
|
||||
const two = screen.getByText('Subject 2').closest('tr')!
|
||||
expect(within(two).getByText(/From header does not match the sender/)).toBeInTheDocument()
|
||||
const three = screen.getByText('Subject 3').closest('tr')!
|
||||
expect(within(three).getByText('—')).toBeInTheDocument() // messages held before this was recorded
|
||||
expect(screen.getByRole('columnheader', { name: /reason/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('says nothing is waiting', async () => {
|
||||
await setup([])
|
||||
expect(await screen.findByText(/nothing is waiting/i)).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export function HeldTab() {
|
|||
<TableHead>From</TableHead>
|
||||
<TableHead>Received</TableHead>
|
||||
<TableHead>Size</TableHead>
|
||||
<TableHead>Reason</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
|
@ -73,6 +74,7 @@ export function HeldTab() {
|
|||
<TableCell>{h.sender}</TableCell>
|
||||
<TableCell>{formatDate(h.created_at)}</TableCell>
|
||||
<TableCell>{formatBytes(h.size)}</TableCell>
|
||||
<TableCell className="max-w-xs whitespace-normal text-muted-foreground">{h.reason || '—'}</TableCell>
|
||||
<TableCell className="space-x-2 text-right">
|
||||
<Button size="sm" disabled={approve.isPending} onClick={() => approve.mutate(h)}>
|
||||
Approve
|
||||
|
|
|
|||
Loading…
Reference in a new issue