Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(storage): warn at export when a file exceeds the per-entry import cap (#1827)

Yudhi Armyndharis7f1469f74072
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 25e7030e8..f67104f9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Warn at storage export when a file is larger than the per-entry import cap `STORAGE_IMPORT_MAX_BYTES`.
- Refuse a `PORT` with surrounding whitespace at boot instead of binding a port the image healthcheck cannot probe.
- Skip or cancel the Baileys version lookup of a session stopped while it connects, so no proxy dispatcher outlives it.
- Stop a request left over from before logout from reloading the dashboard login form.
diff --git a/docs/14-migration-guide.md b/docs/14-migration-guide.md
index bb3709ba7..1ea9a5200 100644
--- a/docs/14-migration-guide.md
+++ b/docs/14-migration-guide.md
@@ -271,7 +271,8 @@ curl -X POST 'http://localhost:2785/api/infra/storage/import' \
The import aborts once it has written more than `STORAGE_IMPORT_MAX_TOTAL_BYTES` (default 10 GiB). For a
larger store, raise it on the destination before Step 5; the export logs a warning when it exceeds that
-limit. An aborted import keeps what it wrote and can be re-run.
+limit. The import also aborts on any single file above `STORAGE_IMPORT_MAX_BYTES` (default 200 MiB), and
+the export warns about that too. An aborted import keeps what it wrote and can be re-run.
| Scenario | Support | Method |
| ---------------------------- | ------- | ------------------------ |
diff --git a/src/common/storage/storage-transfer.spec.ts b/src/common/storage/storage-transfer.spec.ts
index 304e02378..dae8b131f 100644
--- a/src/common/storage/storage-transfer.spec.ts
+++ b/src/common/storage/storage-transfer.spec.ts
@@ -339,3 +339,28 @@ describe('importFromStream caps the total bytes one import writes', () => {
);
});
});
+
+describe('createExportStream and the per-entry import cap', () => {
+ it('warns at export time when one file is larger than the import accepts', async () => {
+ const exportWith = async (cap: string) => {
+ const logger = makeLogger();
+ const prev = process.env.STORAGE_IMPORT_MAX_BYTES;
+ process.env.STORAGE_IMPORT_MAX_BYTES = cap;
+ try {
+ const { openFile } = trackingOpener();
+ const output = await createExportStream(() => Promise.resolve(files.slice(0, 3)), openFile, logger as never);
+ await new Promise<void>(resolve => output.on('end', resolve).resume());
+ } finally {
+ if (prev === undefined) delete process.env.STORAGE_IMPORT_MAX_BYTES;
+ else process.env.STORAGE_IMPORT_MAX_BYTES = prev;
+ }
+ return logger.warn;
+ };
+
+ expect(await exportWith(String(FILE_BYTES))).not.toHaveBeenCalled();
+ const warn = await exportWith(String(FILE_BYTES - 1));
+ expect(warn).toHaveBeenCalledTimes(1);
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('Raise STORAGE_IMPORT_MAX_BYTES'));
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining(`(${FILE_BYTES} bytes)`));
+ });
+});
diff --git a/src/common/storage/storage-transfer.ts b/src/common/storage/storage-transfer.ts
index 0583a38a7..56c976e4c 100644
--- a/src/common/storage/storage-transfer.ts
+++ b/src/common/storage/storage-transfer.ts
@@ -117,6 +117,7 @@ async function appendEntries(
logger: LoggerService,
): Promise<void> {
let exportedBytes = 0;
+ let largest = { file: '', size: 0 };
for (const file of files) {
let source: ExportFileSource;
try {
@@ -132,6 +133,7 @@ async function appendEntries(
}
const { stream, size } = source;
exportedBytes += size ?? 0;
+ if ((size ?? 0) > largest.size) largest = { file, size: size ?? 0 };
// The output closes early when the archive fails or the consumer goes away: stop reading files.
// Checked synchronously before waiting, so a 'close' that already fired cannot be missed.
if (output.destroyed) {
@@ -180,6 +182,16 @@ async function appendEntries(
'Raise STORAGE_IMPORT_MAX_TOTAL_BYTES on the destination before restoring this archive.',
);
}
+ // And for the per-entry cap: one file above it aborts the whole import.
+ const localEntryCap = positiveIntFromEnv('STORAGE_IMPORT_MAX_BYTES', DEFAULT_IMPORT_MAX_BYTES);
+ const warnAboveEntry = Math.min(localEntryCap, DEFAULT_IMPORT_MAX_BYTES);
+ if (largest.size > warnAboveEntry) {
+ logger.warn(
+ `Export contains ${largest.file} (${largest.size} bytes), above the per-entry import limit of ${warnAboveEntry} ` +
+ `(this deployment: ${localEntryCap}, shipped default: ${DEFAULT_IMPORT_MAX_BYTES}). ` +
+ 'Raise STORAGE_IMPORT_MAX_BYTES on the destination before restoring this archive.',
+ );
+ }
// finalize() rejections also emit via the 'error' handler above; catch the promise so it
// never surfaces as an unhandled rejection.
archive.finalize().catch(() => undefined);
@@ -212,8 +224,9 @@ export async function importFromStream(
return new Promise<{ imported: number; failed: number }>((resolve, reject) => {
let settled = false;
- // Abort the whole import: a per-entry or total overflow or too many entries is a (zip-bomb) attack, not
- // a per-file skip — tear down the pipeline and reject so nothing further is buffered or written.
+ // Abort the whole import, not just the entry: a cap breach can be a decompression bomb or a store
+ // larger than the configured limit. Tear down the pipeline and reject so nothing further is buffered
+ // or written.
const fail = (err: Error): void => {
if (settled) return;
settled = true;