Bounded Image Intake Preflight (Node + Python)

    1

    Image decoders size their output from the header, not from the file.

    $29

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Bounded Image Intake Preflight (Node + Python)

    Example session with this skill installed

    I need to validate a user-uploaded PNG in a Node.js API to make sure it is not an animated PNG and does not exceed 1080p dimensions before I process it.

    • Read your context and instructions
    • Compiled the bounded image intake

    I have implemented the preflight check using the provided ESM module. This logic sniffs the PNG header and the acTL chunk (for APNG detection) before any pixel buffer is allocated.

    Node.js Preflight Implementation

    import { preflightImage } from './scripts/image-preflight.mjs';
    
    const limits = {
      maxBytes: 5 * 1024 * 1024, // 5MB
      minEdge: 10,
      maxEdge: 1920,
      maxPixels: 2073600, // 1080p
      allowAnimated: false
    };
    
    try {
      const info = preflightImage(uploadBuffer, limits);
      console.log('Image accepted:', info);
      // Proceed to Sharp/Canvas decoder
    } catch (err) {
      if (err.code === 'ANIMATED_IMAGE_UNSUPPORTED') {
        // Return 400: Animated images not allowed
      } else if (err.code === 'INVALID_IMAGE_DIMENSIONS') {
        // Return 400: Image exceeds 1080p
      }
      console.error(`Refused: ${err.code} - ${err.message}`);
    }
    

    Next steps

    1. Copy scripts/image-preflight.mjs into your project's utility folder.
    2. Update your Express or Fastify error handler to map INVALID_IMAGE_DIMENSIONS to an HTTP 400 status.
    3. Run the provided test suite with node --test scripts/preflight.test.mjs to verify your environment.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Image decoders size their output from the header, not from the file. A 300-byte PNG that claims 60,000 x 60,000 pixels asks for about 14 GB; an animated WebP multiplies that by its frame count. Any service that hands uploads straight to a decoder can be stalled by a trivial request.

    Preflight (image-preflight.mjs, image_preflight.py): reads only the header to learn format and dimensions: PNG IHDR with APNG acTL detection; JPEG marker walk to the first start-of-frame (baseline, extended, progressive, lossless, arithmetic) skipping fill bytes and standalone markers; WebP VP8X (animation flag), VP8 and VP8L. Enforces maxBytes, minEdge, maxEdge, maxPixels and allowAnimated with the codes INVALID_IMAGE_FORMAT, INVALID_IMAGE_DIMENSIONS, ANIMATED_IMAGE_UNSUPPORTED, IMAGE_TOO_LARGE. Same behavior in both languages; both have a CLI that prints one JSON line per file and exits 1 on any refusal.

    Binary frame (binary-frame.mjs): one body carries a JSON metadata object and 1 to N binary parts behind a fixed header (magic, part count, metadata length, one 32-bit length per part). The decoder checks every length against your ceilings, requires the lengths to sum to the body exactly, and returns zero-copy views. maxFrameBytes(limits) gives the body ceiling for the route and the reverse proxy.

    Tests: 5 Node tests (all formats, animation, truncation, a lying SOF length, ceilings, frame round trip and nine malformed frames, Node/Python CLI agreement) and 3 Python tests, with synthetic header fixtures you can reuse. reference/limits.md explains each default and how to tune it from your memory budget.

    Node 20+ or Python 3.10+, no packages, no network.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Supports PNG, JPEG, and WebP only. Refuses GIF, HEIC, AVIF, and SVG. Does not apply EXIF orientation. Memory-safe for headers only; decoders still need error handling for pixel data.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 17 days ago

    Software
    Node.js 20+
    orPython 3.10+

    Permissions

    Read Files
    Listed17 days ago

    What's inside

    Frequently Asked Questions

    This skill prevents "pixel-bomb" DoS attacks by inspecting image headers to verify dimensions and pixel counts before your system allocates memory for full decoding. Unlike standard file-size checks, it catches small, malicious files designed to crash your server by claiming massive dimensions.

    The skill includes native implementations for both Node.js (20+ ESM) and Python (3.10+). Both versions are designed with zero external dependencies, making them easy to integrate into existing AI agent workflows or microservices without bloating your environment.

    You will receive the source code for the header-only sniffers in both Node.js and Python, the binary framing utility for efficient uploads, and a comprehensive guide on mapping refusal codes to HTTP responses.

    This skill focuses on the most common web formats: PNG, APNG, JPEG, and WebP. It does not currently support GIF, HEIC, AVIF, or vector-based formats like SVG.

    No, the preflight check is a non-destructive header analysis that does not modify the image. It simply validates metadata; you will still need to use a library like Sharp or Pillow for the final decoding and processing steps.

    By using the included binary framing utility, you can pack metadata and multiple image buffers into a single contiguous block. This bypasses the heavy CPU and memory overhead associated with multipart/form-data parsing or Base64 encoding.

    New in APIs & Backend