Dev.to Security 🔐 Cybersecurity 👁 0 📖 5 min read

Why Pixelation Fails Against Depix — and Building a Zero-Upload HTML5 Canvas Redactor

When users look for an online tool to edit or hide text in a screenshot, the word "online" hides two totally opposite privacy models: Cloud inference: the image leaves your device over HTTPS, lands in object storage,

When users look for an online tool to edit or hide text in a screenshot, the word "online" hides two totally opposite privacy models:

  1. Cloud inference: the image leaves your device over HTTPS, lands in object storage, and runs through a GPU model.
  2. Client-side HTML5 Canvas: the image is decoded in browser memory, redrawn locally, and exported as a flattened PNG/JPEG with zero network requests.

Disclosure: I build EditTextImage (edittextimage.com) — SparkTech's pixel-level AI typography redraw editor (not a browser OCR overlay, and unaffiliated with lookalike domains such as edittextimage.net). Because EditTextImage ships both architectures on the same site, we had to be explicit about where each boundary sits.

Here are the engineering trade-offs, two subtle Safari Canvas traps we hit while building our zero-upload redactor, why mosaic pixelation fails against Depix, and how we structure order-safe 7-day deletion for our cloud AI modes.

1. Why mosaic pixelation fails against Depix

Many screenshot tools default to a mosaic/pixelate filter when users want to hide an API key, password, or email address.

That is risky for short, known-font text. A standard box pixelation filter computes the deterministic average color of each N × N block. The open-source research tool Depix demonstrated that pixelated monospace and standard UI screenshots can be attacked by rendering candidate character strings, passing them through the same box filter, and matching the resulting block colors back to the redacted image.

Gaussian or downscale blur has a related flaw: at moderate radii it still leaks character count, descenders, and high-contrast digit silhouettes.

For anything genuinely sensitive (passwords, API keys, card numbers, private tokens), the only irreversible pixel-level redaction is an opaque solid black rectangle (#000) exported as a flattened raster image (PNG/JPEG) so no underlying pixels or editable layers survive.

2. Building a 100% zero-upload Canvas redactor (and two Safari traps)

On /blur-text-in-image and /pixelate-image, we made a hard architectural rule: no sign-in, no credits, no fetch, no upload, and no analytics payload carrying pixels.

Two real-world Safari bugs immediately broke the naive implementation:

Trap A: iOS Safari renders canvases above ~16.7 MP completely blank

A modern 48 MP iPhone photo easily crosses iOS Safari's ~16.7 megapixel canvas memory ceiling, and Safari fails silently by rendering a blank white/transparent export. Before drawing anything, we cap the internal working canvas to 16_000_000 pixels:

const MAX_PIXELS = 16_000_000;

const bitmap = await createImageBitmap(file, { imageOrientation: "from-image" });
const scale = Math.min(1, Math.sqrt(MAX_PIXELS / (bitmap.width * bitmap.height)));

const base = document.createElement("canvas");
base.width = Math.max(1, Math.round(bitmap.width * scale));
base.height = Math.max(1, Math.round(bitmap.height * scale));
base.getContext("2d")!.drawImage(bitmap, 0, 0, base.width, base.height);

Notice imageOrientation: "from-image" too — without it, portrait phone photos with EXIF rotation flags can render sideways on export. For iPhone HEIC files opened in non-Safari desktop browsers, we fall back to a local in-browser WebAssembly decoder so files still never leave the device.

Trap B: ctx.filter = "blur()" isn't reliable on older Safari 2D canvases

Instead of relying on CanvasRenderingContext2D.filter, we build both Blur and Pixelate from offscreen downscale → upscale passes:

function applyEffect(
  ctx: CanvasRenderingContext2D,
  base: HTMLCanvasElement,
  x: number,
  y: number,
  w: number,
  h: number,
  mode: "blur" | "pixelate" | "solid",
  strength: number
) {
  if (mode === "solid") {
    ctx.fillStyle = "#000";
    ctx.fillRect(x, y, w, h);
    return;
  }

  const minSide = Math.min(base.width, base.height);

  if (mode === "pixelate") {
    const block = Math.max(2, Math.round(minSide * (0.004 + strength * 0.004)));
    const small = makeCanvas(Math.ceil(w / block), Math.ceil(h / block));
    const sctx = small.getContext("2d")!;
    sctx.imageSmoothingEnabled = true;
    sctx.drawImage(base, x, y, w, h, 0, 0, small.width, small.height);

    ctx.save();
    ctx.imageSmoothingEnabled = false; // crisp mosaic blocks
    ctx.drawImage(small, 0, 0, small.width, small.height, x, y, w, h);
    ctx.restore();
    return;
  }

  // Blur: two halving stages down, then upscale with high-quality smoothing
  const factor = Math.max(2, Math.round(minSide * (0.003 + strength * 0.003)));
  const mid = makeCanvas(w / Math.sqrt(factor), h / Math.sqrt(factor));
  const tiny = makeCanvas(w / factor, h / factor);
  const mctx = mid.getContext("2d")!;
  const tctx = tiny.getContext("2d")!;
  mctx.imageSmoothingQuality = "high";
  tctx.imageSmoothingQuality = "high";

  mctx.drawImage(base, x, y, w, h, 0, 0, mid.width, mid.height);
  tctx.drawImage(mid, 0, 0, tiny.width, tiny.height);
  mctx.clearRect(0, 0, mid.width, mid.height);
  mctx.drawImage(tiny, 0, 0, mid.width, mid.height);

  ctx.save();
  ctx.imageSmoothingEnabled = true;
  ctx.imageSmoothingQuality = "high";
  ctx.drawImage(mid, 0, 0, mid.width, mid.height, x, y, w, h);
  ctx.restore();
}

Why two downscale stages for blur? A single steep downscale produces boxy artifacts when upscaled back; splitting across sqrt(factor) keeps the blur smooth across Chrome, Firefox, and Safari alike.

How to verify zero upload yourself

You never have to trust a web app's privacy claims:

  1. Load edittextimage.com/blur-text-in-image.
  2. Open DevTools → Network → check Preserve log → switch throttling to Offline.
  3. Drop a screenshot, draw a Black box, and click Download.

Zero POST/PUT requests leave your browser, and the flattened redacted PNG still downloads while offline.

3. Order-safe 7-day deletion for cloud AI edits

Of course, generative typography redraw — fixing a garbled Midjourney sign, translating a 1688 product infographic, or matching a custom game HUD font — cannot run in a browser tab. Those cloud modes upload inputs to Cloudflare R2 and send them transiently to our inference provider (never used for model training, per our Privacy Policy).

One small backend detail worth sharing if you build file-processing SaaS apps: always delete object storage keys before deleting database task rows, and derive variant keys deterministically rather than trusting optional metadata JSON columns.

In our daily 04:00 UTC retention cron (RETENTION_DAYS = 7):

  1. Query expired edit_tasks rows older than 7 days (computing the cutoff DB-side so timezone offsets cannot quietly stretch retention).
  2. Collect the input key, output key, and deterministically derived preview + full-JPEG variant keys (even if an interrupted upload never wrote meta.previewUrl, DeleteObjects treats missing keys as a safe no-op).
  3. Call deleteFromR2(keys) first. If R2 throws, abort and leave the DB rows intact so the next cron invocation retries cleanly.
  4. Only after R2 confirms deletion, remove the edit_tasks rows (keeping separate payment/credit tables intact).

When NOT to upload to any cloud image editor

  • Live credentials (passwords, API keys, seed phrases, OAuth tokens) — redact locally with a solid black box before sharing, and rotate exposed keys.
  • Strict NDA / medical / customer PII screenshots — stick to local browser Canvas redaction or offline desktop tools (GIMP, Preview, Photoshop).
  • IDs, bank records, receipts, certificates — prohibited under EditTextImage's Acceptable Use Policy.

Full user-facing guide (including the privacy comparison table and FAQ):
Online Image Text Editor Privacy: Cloud vs. Zero-Upload

Official EditTextImage endpoints: edittextimage.com · iOS App · Android App · Chrome Extension.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.