Skip to content

Commit 47d4366

Browse files
committed
fix: validate fileDownloadURL format in file download handler
1 parent 037766e commit 47d4366

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PluginOptions } from './types.js';
33
import { AdminForthPlugin, AdminForthResourceColumn, AdminForthResource, Filters, IAdminForth, IHttpServer, suggestIfTypo } from "adminforth";
44
import { Readable } from "stream";
55
import { RateLimiter } from "adminforth";
6-
import { url } from 'inspector/promises';
76

87
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
98

@@ -439,6 +438,10 @@ export default class UploadPlugin extends AdminForthPlugin {
439438
return { error: 'Missing fileDownloadURL' };
440439
}
441440

441+
if (!fileDownloadURL.startsWith(`http://${(this.options.storageAdapter as any).options.bucket}`) && !fileDownloadURL.startsWith(`https://${(this.options.storageAdapter as any).options.bucket}`)) {
442+
return { error: 'Invalid fileDownloadURL ' };
443+
}
444+
442445
const upstream = await fetch(fileDownloadURL);
443446
if (!upstream.ok || !upstream.body) {
444447
return { error: `Failed to download file (status ${upstream.status})` };

0 commit comments

Comments
 (0)