From 4a9da3a94a4e0a8ca79998f6bfd9a0dbb768e8ec Mon Sep 17 00:00:00 2001 From: Henner4746 <145707117+Henner4746@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:07:57 +0100 Subject: [PATCH] fix(attachments): ask before sending a file whose metadata BitDM cannot remove Only JPEG, PNG, WebP, HEIC/AVIF and MP4/MOV are cleaned. PDF, Office/ODF and other ZIP files, GIF, TIFF (with GPS), MP3, Matroska/WebM, Ogg, FLAC, WAV/AVI and unknown ISO brands such as M4A went out with all metadata and their original name, without a word (security assessment 2026-11-23, SEC-M3). traegtUnentfernteMetadaten() recognises these by their first bytes. Sending one now asks the same "Send it anyway?" question as an image that could not be cleaned, with its own text naming what goes along (author, software, times, sometimes location, file name). The file name is kept: for a document it is usually wanted. Voice messages are excluded as before; files without a known signature are not asked about. Co-Authored-By: Claude Opus 5.5 --- secure-messenger/app/lib/app_state.dart | 9 +++- .../app/lib/core/anhang/metadaten.dart | 34 +++++++++++++++ secure-messenger/app/lib/data.dart | 2 + .../app/lib/oberflaeche/home.dart | 7 +++- .../app/test/anhang/metadaten_test.dart | 34 +++++++++++++++ .../test/oberflaeche/sperre_zustand_test.dart | 41 +++++++++++++++++++ 6 files changed, 125 insertions(+), 2 deletions(-) diff --git a/secure-messenger/app/lib/app_state.dart b/secure-messenger/app/lib/app_state.dart index 352d331..ec67f88 100644 --- a/secure-messenger/app/lib/app_state.dart +++ b/secure-messenger/app/lib/app_state.dart @@ -2650,7 +2650,14 @@ class AppState extends ChangeNotifier { // Versand selbst mit einer eigenen Meldung. return nichts; } - if (!istBereinigbar(kopf)) return nichts; + if (!istBereinigbar(kopf)) { + // NICHT STILL: eine Art, deren Metadaten hier nicht entfernt werden. + // Der Name bleibt (bei einem Dokument will man ihn meist), aber der + // Nutzer erfaehrt vorher, dass Autor, Zeiten und Name mitgehen. + return traegtUnentfernteMetadaten(kopf) + ? (datei: null, name: null, warnung: 'metaUnbekannt') + : nichts; + } final zufall = Random.secure().nextInt(0x10000); final neutral = neutralerBildname(kopf, zufall); final video = istVideo(kopf); diff --git a/secure-messenger/app/lib/core/anhang/metadaten.dart b/secure-messenger/app/lib/core/anhang/metadaten.dart index 6aad988..cfac77d 100644 --- a/secure-messenger/app/lib/core/anhang/metadaten.dart +++ b/secure-messenger/app/lib/core/anhang/metadaten.dart @@ -161,6 +161,40 @@ Uint8List? ohneMetadaten(Uint8List b, {bool vorOrt = false}) => bool istBereinigbar(Uint8List b) => _istJpeg(b) || _istPng(b) || _istWebp(b) || _isoArt(b) != null; +/// Ob die Datei zu einer Art gehoert, die Metadaten traegt, die hier NICHT +/// entfernt werden — erkannt am Dateianfang, nicht an der Endung. +/// +/// PDF (Autor, Software, Zeiten), Office- und ODF-Dateien sowie ZIP +/// (Autor, Bearbeiter, Zeiten, Pfade), GIF (Kommentare, XMP), TIFF (EXIF, +/// auch GPS), MP3 (ID3), Matroska/WebM, Ogg, FLAC, WAV/AVI (INFO) und +/// ISO-Dateien, deren Marke [bereinige] nicht kennt (etwa M4A). Bis +/// 23.11.2026 gingen sie ohne ein Wort hinaus (Sicherheitsbewertung vom +/// 23.11.2026, SEC-M3); jetzt fragt die App. Eine Datei ohne bekannte +/// Kennung (Text, Rohdaten) bleibt ohne Rueckfrage. +bool traegtUnentfernteMetadaten(Uint8List b) { + if (istBereinigbar(b)) return false; + bool beginnt(List kennung, [int ab = 0]) { + if (b.length < ab + kennung.length) return false; + for (var i = 0; i < kennung.length; i++) { + if (b[ab + i] != kennung[i]) return false; + } + return true; + } + + return beginnt(const [0x25, 0x50, 0x44, 0x46]) || // %PDF + beginnt(const [0x50, 0x4B, 0x03, 0x04]) || // ZIP: docx, xlsx, odt, ... + beginnt(const [0x47, 0x49, 0x46, 0x38]) || // GIF8 + beginnt(const [0x49, 0x49, 0x2A, 0x00]) || // TIFF (II*) + beginnt(const [0x4D, 0x4D, 0x00, 0x2A]) || // TIFF (MM*) + beginnt(const [0x49, 0x44, 0x33]) || // MP3 mit ID3 + (b.length > 1 && b[0] == 0xFF && (b[1] & 0xE0) == 0xE0 && !_istJpeg(b)) || // MPEG-Audio + beginnt(const [0x1A, 0x45, 0xDF, 0xA3]) || // Matroska / WebM + beginnt(const [0x4F, 0x67, 0x67, 0x53]) || // Ogg + beginnt(const [0x66, 0x4C, 0x61, 0x43]) || // FLAC + beginnt(const [0x52, 0x49, 0x46, 0x46]) || // RIFF (WAV, AVI; WebP ist bereinigbar) + beginnt(const [0x66, 0x74, 0x79, 0x70], 4); // ftyp, unbekannte Marke +} + /// Ob die Datei ein Video ist (MP4, MOV, 3GP, M4V). Dafuer reicht der /// Dateianfang — die ersten paar hundert Bytes mit dem ftyp-Kasten. bool istVideo(Uint8List b) => _isoArt(b) == _IsoArt.video; diff --git a/secure-messenger/app/lib/data.dart b/secure-messenger/app/lib/data.dart index c9804e4..d115439 100644 --- a/secure-messenger/app/lib/data.dart +++ b/secure-messenger/app/lib/data.dart @@ -567,6 +567,7 @@ const Map> strings = { 'wipeChangeAsk': 'Change or turn off remote wipe?', 'metaAskTitle': 'Metadata stays in the file', 'metaTooBig': 'This file is too large to remove its metadata (location, camera, time). Send it anyway?', + 'metaKept': 'BitDM cannot remove the metadata from this kind of file (documents, GIF, TIFF, audio, MKV/WebM). Author, software, times, sometimes the location, and the file name go along. Send it anyway?', 'metaFailed': 'The metadata (location, camera, time) could not be removed from this file. Send it anyway?', 'metaNotRemoved': 'Not sent: the metadata could not be removed.', 'sendAnyway': 'Send anyway', @@ -1003,6 +1004,7 @@ const Map> strings = { 'wipeChangeAsk': 'Fernlöschung ändern oder ausschalten?', 'metaAskTitle': 'Metadaten bleiben in der Datei', 'metaTooBig': 'Diese Datei ist zu groß, um ihre Metadaten (Ort, Kamera, Zeit) zu entfernen. Trotzdem senden?', + 'metaKept': 'Aus dieser Art Datei (Dokumente, GIF, TIFF, Audio, MKV/WebM) kann BitDM die Metadaten nicht entfernen. Autor, Programm, Zeiten, manchmal der Ort und der Dateiname gehen mit. Trotzdem senden?', 'metaFailed': 'Die Metadaten (Ort, Kamera, Zeit) ließen sich aus dieser Datei nicht entfernen. Trotzdem senden?', 'metaNotRemoved': 'Nicht gesendet: die Metadaten ließen sich nicht entfernen.', 'sendAnyway': 'Trotzdem senden', diff --git a/secure-messenger/app/lib/oberflaeche/home.dart b/secure-messenger/app/lib/oberflaeche/home.dart index d7ec3f1..a35ac28 100644 --- a/secure-messenger/app/lib/oberflaeche/home.dart +++ b/secure-messenger/app/lib/oberflaeche/home.dart @@ -715,7 +715,12 @@ class _HomeState extends State with WidgetsBindingObserver, TickerProvider builder: (ctx) => AlertDialog( key: const ValueKey('meta-frage'), title: Text(t('metaAskTitle')), - content: Text(grund == 'metaZuGross' ? t('metaTooBig') : t('metaFailed'), + content: Text( + switch (grund) { + 'metaZuGross' => t('metaTooBig'), + 'metaUnbekannt' => t('metaKept'), + _ => t('metaFailed'), + }, style: mono(size: 12, color: p.muted, height: 1.5)), actions: [ TextButton(onPressed: () => Navigator.pop(ctx, false), child: Text(t('cancel'))), diff --git a/secure-messenger/app/test/anhang/metadaten_test.dart b/secure-messenger/app/test/anhang/metadaten_test.dart index fcde476..82547a4 100644 --- a/secure-messenger/app/test/anhang/metadaten_test.dart +++ b/secure-messenger/app/test/anhang/metadaten_test.dart @@ -276,6 +276,40 @@ void main() { // ob das Bereinigen gescheitert ist — im zweiten Fall geht die Datei MIT // Metadaten hinaus, und der Nutzer soll davon wissen. + group('SEC-M3: Arten, deren Metadaten hier NICHT entfernt werden', () { + Uint8List mit(List anfang) => + Uint8List.fromList([...anfang, ...List.filled(64, 0x20)]); + + test('werden am Dateianfang erkannt, nicht an der Endung', () { + final arten = >{ + 'PDF': '%PDF-1.7'.codeUnits, + 'DOCX/ODT (ZIP)': [0x50, 0x4B, 0x03, 0x04], + 'GIF': 'GIF89a'.codeUnits, + 'TIFF II': [0x49, 0x49, 0x2A, 0x00], + 'TIFF MM': [0x4D, 0x4D, 0x00, 0x2A], + 'MP3 ID3': 'ID3'.codeUnits, + 'MP3 Rahmen': [0xFF, 0xFB, 0x90, 0x00], + 'MKV/WebM': [0x1A, 0x45, 0xDF, 0xA3], + 'Ogg': 'OggS'.codeUnits, + 'FLAC': 'fLaC'.codeUnits, + 'WAV': [...'RIFF'.codeUnits, 0, 0, 0, 0, ...'WAVE'.codeUnits], + 'M4A': [0, 0, 0, 0x18, ...'ftypM4A '.codeUnits], + }; + for (final e in arten.entries) { + expect(traegtUnentfernteMetadaten(mit(e.value)), isTrue, reason: e.key); + } + }); + + test('was bereinigt wird oder keine Kennung hat, gilt nicht', () { + expect(traegtUnentfernteMetadaten(mit([0xFF, 0xD8, 0xFF, 0xE0])), isFalse, + reason: 'JPEG wird bereinigt'); + expect(traegtUnentfernteMetadaten(mit([...'RIFF'.codeUnits, 0, 0, 0, 0, ...'WEBP'.codeUnits])), + isFalse, reason: 'WebP wird bereinigt'); + expect(traegtUnentfernteMetadaten(mit('Hallo, das ist Text'.codeUnits)), isFalse); + expect(traegtUnentfernteMetadaten(Uint8List(0)), isFalse); + }); + }); + group('bereinige', () { test('die vier Faelle', () { expect(bereinige(probe('mit_gps.jpg')), isA()); diff --git a/secure-messenger/app/test/oberflaeche/sperre_zustand_test.dart b/secure-messenger/app/test/oberflaeche/sperre_zustand_test.dart index 3377eae..7be0be0 100644 --- a/secure-messenger/app/test/oberflaeche/sperre_zustand_test.dart +++ b/secure-messenger/app/test/oberflaeche/sperre_zustand_test.dart @@ -321,6 +321,47 @@ void main() { expect(st.verlaufVon(c).last.text, matches(RegExp(r'^bild-[0-9a-f]{4}\.jpg$'))); }); + test('SEC-M3: EIN PDF GEHT NICHT MEHR OHNE WORT HINAUS', () async { + // Bis 23.11.2026: PDF, Office, GIF, TIFF (mit GPS), MP3, MKV/WebM + // behielten alle Metadaten und den Namen, ohne Hinweis. + final c = ersterKontakt(); + await st.unterhaltungOeffnen(c); + final gruende = []; + var antwort = false; + st.frageOhneBereinigung = (g) async { + gruende.add(g); + return antwort; + }; + final f = File('${verzeichnis.path}/Vertrag.pdf') + ..writeAsBytesSync([...'%PDF-1.7 '.codeUnits, ...List.filled(300, 0x20)]); + final vorher = st.verlaufVon(c).length; + await st.anhangSenden(c, f, name: 'Vertrag.pdf'); + expect(gruende, ['metaUnbekannt']); + expect(st.verlaufVon(c).length, vorher, reason: 'Nein schickt nichts'); + + antwort = true; + await st.anhangSenden(c, f, name: 'Vertrag.pdf'); + expect(st.verlaufVon(c).last.text, 'Vertrag.pdf', + reason: 'bei einem Dokument bleibt der Name — der Nutzer weiss es jetzt'); + }); + + test('SEC-M3: OHNE RUECKFRAGE GEHT EIN PDF NICHT HINAUS, ROHDATEN SCHON', () async { + final c = ersterKontakt(); + await st.unterhaltungOeffnen(c); + final pdf = File('${verzeichnis.path}/a.pdf') + ..writeAsBytesSync([...'%PDF-1.4'.codeUnits, ...List.filled(300, 0x20)]); + await st.anhangSenden(c, pdf, name: 'a.pdf'); + expect(st.letzterFehler, 'metaNichtEntfernt'); + + st.vergissFehler(); + final roh = File('${verzeichnis.path}/daten.bin') + ..writeAsBytesSync(List.filled(400, 0x07)); + final vorher = st.verlaufVon(c).length; + await st.anhangSenden(c, roh, name: 'daten.bin'); + expect(st.letzterFehler, isNull, reason: 'Rohdaten ohne Kennung: keine Frage'); + expect(st.verlaufVon(c).length, vorher + 1); + }); + test('zu gross zum Bereinigen: der Nutzer wird gefragt', () async { final c = ersterKontakt(); final gruende = [];