fix: Dateinamen mit Pfadtrennzeichen beim Mail-Import absichern
Build and Push Multi-Platform Images / build-and-push (push) Successful in 31s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 31s
Anhänge mit '/' im Dateinamen (z.B. "Rechnung - 2026/002650322.PDF") führten zu einem Fehler, weil '/' als Verzeichnistrenner interpretiert wurde und der temp. Pfad nicht existierte. - sanitizeFilename() ersetzt '/' und '\' durch '-', entfernt '..' und Null-Bytes - Wird beim Speichern in die DB (email-download) und beim Aufbau des temp. Pfads (email-import) angewendet (defense-in-depth) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,14 @@ import { Attachment } from '../database/entities/attachment.entity';
|
|||||||
import { Content } from '../database/entities/content.entity';
|
import { Content } from '../database/entities/content.entity';
|
||||||
import { isERechnung } from './zugferd.util';
|
import { isERechnung } from './zugferd.util';
|
||||||
|
|
||||||
|
function sanitizeFilename(name: string): string {
|
||||||
|
return name
|
||||||
|
.replace(/[/\\]/g, '-')
|
||||||
|
.replace(/\.\./g, '.')
|
||||||
|
.replace(/\x00/g, '')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmailDownloadService {
|
export class EmailDownloadService {
|
||||||
private readonly logger = new Logger(EmailDownloadService.name);
|
private readonly logger = new Logger(EmailDownloadService.name);
|
||||||
@@ -291,7 +299,7 @@ export class EmailDownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const attachment = new Attachment();
|
const attachment = new Attachment();
|
||||||
attachment.FileName = filename.slice(0, 255);
|
attachment.FileName = sanitizeFilename(filename).slice(0, 255);
|
||||||
attachment.ContentType = contentType.slice(0, 100);
|
attachment.ContentType = contentType.slice(0, 100);
|
||||||
attachment.IsEmbedded = isEmbedded;
|
attachment.IsEmbedded = isEmbedded;
|
||||||
attachment.ContentId = att.cid ? att.cid.slice(0, 255) : null;
|
attachment.ContentId = att.cid ? att.cid.slice(0, 255) : null;
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ import * as os from 'os';
|
|||||||
import * as fs from 'fs/promises';
|
import * as fs from 'fs/promises';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
|
function sanitizeFilename(name: string): string {
|
||||||
|
return name
|
||||||
|
.replace(/[/\\]/g, '-')
|
||||||
|
.replace(/\.\./g, '.')
|
||||||
|
.replace(/\x00/g, '')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EmailImportService {
|
export class EmailImportService {
|
||||||
private readonly logger = new Logger(EmailImportService.name);
|
private readonly logger = new Logger(EmailImportService.name);
|
||||||
@@ -492,7 +500,7 @@ export class EmailImportService {
|
|||||||
if (!content) continue;
|
if (!content) continue;
|
||||||
|
|
||||||
const originalPdfBytes = content.Content1;
|
const originalPdfBytes = content.Content1;
|
||||||
const baseFilename = attachmentEntity.FileName.replace(/\.pdf$/i, '');
|
const baseFilename = sanitizeFilename(attachmentEntity.FileName.replace(/\.pdf$/i, ''));
|
||||||
const paperlessIds: any = {};
|
const paperlessIds: any = {};
|
||||||
|
|
||||||
const uploadPromises = [];
|
const uploadPromises = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user