Developer builds custom PNG decoder to add QR code phishing scanner to Cloudflare Workers API

A developer at Presend built a QR code phishing detection endpoint for their API that decodes uploaded images and checks embedded URLs against a malware database. Because the API runs on Cloudflare Workers, standard Node.js libraries like pngjs were unavailable, forcing a custom PNG decoder to be written from scratch using the runtime's native DecompressionStream API. The project required manually implementing PNG chunk parsing, scanline filter reversal, and pixel reassembly. A critical bug was discovered during testing: most QR code generators output 1-bit PNGs by default, but the decoder had only been built and validated against 8-bit images, meaning it would have failed on the majority of real-world inputs. The fix involved adding support for sub-byte pixel packing, where multiple pixels are stored within a single byte, padded per scanline as specified in the PNG standard.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in