Skip to content
masterclass BuddyTech Buzz5 fresh blogs Β· every Monday

A Pentest Report Just Flagged Our Avatar Uploads: The SVG Decision We Got Wrong

Learn to pick the right SVG delivery method in Next.js for icons, illustrations and uploads, with secure config that won't fail a pentest.

MCB Editorial

Tech Buzz Community Desk Β· 9 min read Β·

New story

Inspired by β€œThree ways to use SVG in Next.js and when each one wins” by SVG to React on Medium. Rewritten and expanded by MCB Editorial.

Narrated by Study Buddy Narration
Voiceover Engine β€’ Interactive Audio Sync
0:009:00

Learning Objectives & Key Takeaways

0 / 4 Completed
Architecture Ready
100%
What you will learn
  1. Next.js never optimizes SVG by default, and next/image applies unoptimized automatically for .svg sources.
  2. Inline SVG gives CSS full access to paths and strokes, but it shares the page's id namespace and bloats the bundle for large files.
  3. @svgr/webpack turns .svg imports into components through a Turbopack rule that maps .svg to as: '.js'.
  4. Never render user-uploaded SVG as inline React markup, since SVG can carry scripts that execute the moment it mounts.
  5. dangerouslyAllowSVG only belongs in your config alongside contentDispositionType: attachment and a script-blocking CSP.

The Pentest Finding That Started With an Avatar

Our security vendor sent a one-line finding that ruined a Friday afternoon: stored cross-site scripting through profile picture uploads. Someone had uploaded an SVG file as an avatar, and our app rendered it directly as inline React markup.

The SVG looked like a harmless vector icon in the file browser, but it carried an embedded script tag that fired the moment the component mounted. Every teammate who opened that profile ran the attacker's code inside their own session.

In the rest of this story
  1. Three Ways an SVG Reaches the Page, and Why They Behave Differently
  2. Static Delivery for Illustrations, Logos and Anything You Won't Restyle
  3. Inline Components for Icons That Need to Match Your UI
  4. Wiring SVGR Into next.config.ts for a Growing Icon Set
  5. Locking Down SVG You Don't Control
2 code examples Β· 9 min read in full
Member-only story

Checking your membership…

Members read every Tech Buzz story in full, with code examples, audio and the discussion, plus every course, quiz and interview set in the Learning Dashboard.

0

Written by

MCB Editorial

Tech Buzz Community Desk. Contributing deep-dive engineering architectures, cloud paradigms, and system design insights to Master Class Buddy.