taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit f539398a77d3985b5fa6fe8b77f2a62f904fb875
parent 7563d0034f1a3f5e2eebf8b547a17900ff4f9658
Author: Marc Stibane <marc@taler.net>
Date:   Thu, 20 Aug 2026 19:46:08 +0200

AI: limit logo/image size

Diffstat:
MTalerCommon/Helper/Image+fallback.swift | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/TalerCommon/Helper/Image+fallback.swift b/TalerCommon/Helper/Image+fallback.swift @@ -39,6 +39,13 @@ extension Image { /// the main thread and telling the merchant when (and how often) the user looks at /// the transaction - or read a local file for a `file:` URL. init?(imageBase64: String) { + // The data URL comes from merchant-controlled contract terms (merchant.logo, + // product.image). Reject anything implausibly large before decoding it, so a + // malicious merchant can't force us to allocate an unbounded buffer just to + // render a payment/transaction screen. + let maxDataUrlLength = 1 * 1024 * 1024 // ~3/4 MB decoded, generous for a logo/product image + guard imageBase64.utf8.count <= maxDataUrlLength else { return nil } + let anchored: String.CompareOptions = [.caseInsensitive, .anchored] guard let dataUrlPrefix = imageBase64.range(of: "data:image/png;base64,", options: anchored) ?? imageBase64.range(of: "data:image/jpeg;base64,", options: anchored),