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

The Login Screen Everyone Saw, Except the PDF Behind It

Learn to lock pages, downloads, and even optimized images at the Next.js proxy layer with correct 401 and 503 responses.

MCB Editorial

Tech Buzz Community Desk Β· 9 min read Β·

New story

Inspired by β€œProtecting Pages and Files with Next.js Proxy” by Victor Yan 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 16 renames middleware.ts to proxy.ts without changing how request interception works.
  2. A matcher protecting a page can still leak its PDF or optimized image if routes aren't listed explicitly.
  3. Return 401 with a WWW-Authenticate header for missing or wrong credentials, never a redirect.
  4. Reserve 503 for a missing or misconfigured password, not for routine unauthenticated requests.
  5. Strip the Authorization header before forwarding so it never reaches your page or API logic.

The Article Page Was Locked. The PDF Was Not.

At BeyondClass, our HSC practice platform, I needed a small editorial workspace where a handful of writers could draft articles, attach PDFs and diagram exports, and review HTML previews before anything went live elsewhere. Building a full account system for four or five people felt like over-engineering, so a shared password for the group seemed like the right amount of friction. I put a login check in front of the article page component and moved on, assuming the page was now private.

A few days later someone pasted a direct link to one of the PDFs into a chat, and it opened without ever asking for a password. The file lived under public/articles, so Next.js was serving it as a static asset straight from the filesystem, completely outside the component that checked for a session. The page looked locked. The content behind it was not.

In the rest of this story
  1. Define the URL Boundary First, Not the Component
  2. Build the Challenge-Response Gate
  3. 401 Means Try Again, 503 Means Something Is Broken
  4. Close the Image-Optimizer Bypass
  5. Test the Full Surface, Then Know the Limits
1 code example Β· 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.