fix(totp): validate qr image uploads

This commit is contained in:
shuaiplus
2026-07-05 23:44:44 +08:00
parent cf14704d99
commit 6e722205b1
@@ -67,6 +67,8 @@ interface WebsiteRowProps {
onRemove: (index: number) => void; onRemove: (index: number) => void;
} }
const TOTP_QR_IMAGE_MAX_BYTES = 8 * 1024 * 1024;
function WebsiteRow(props: WebsiteRowProps) { function WebsiteRow(props: WebsiteRowProps) {
const websiteMatchOptions = getWebsiteMatchOptions(); const websiteMatchOptions = getWebsiteMatchOptions();
@@ -208,6 +210,14 @@ export default function VaultEditor(props: VaultEditorProps) {
const handleTotpQrFile = async (file: File | null) => { const handleTotpQrFile = async (file: File | null) => {
if (!file) return; if (!file) return;
if (file.type && !file.type.startsWith('image/')) {
setTotpQrStatus(t('txt_totp_qr_invalid_image_type'));
return;
}
if (file.size > TOTP_QR_IMAGE_MAX_BYTES) {
setTotpQrStatus(t('txt_totp_qr_image_too_large'));
return;
}
setTotpQrBusy(true); setTotpQrBusy(true);
setTotpQrStatus(t('txt_totp_qr_scanning')); setTotpQrStatus(t('txt_totp_qr_scanning'));
let bitmap: ImageBitmap | null = null; let bitmap: ImageBitmap | null = null;