Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Build a Next.js App That's Harder to Break in Penetration Testing ๐Ÿ”

You ship your Next.js app. It looks great and the Lighthouse score is green. Then a penetration tester sends you a report, and it's longer than your README. It happens to many of us. Security often feels like something to "add later," right after the feature is done. Later usually arrives as a surprise. So here's a question: what if your next pen test came back with only a few small notes insteadโ€ฆ

Building a secure Next.js app involves more than just completing features and green Lighthouse scores. Penetration testers often find numerous issues after development is done, making security an ongoing process. This article outlines practical steps to build a Next.js app that is harder to penetrate through regular testing.

First, understand what "hard to penetrate" truly means. In penetration testing, security experts try to break into your app as a real attacker would. Your app's "doors" include login forms, API routes, and any other areas that handle user data. The "locks" refer to authentication, authorization, logging, and monitoring systems. The goal is to have strong locks, minimal unnecessary access points, and to keep sensitive data off the front porch where it's easily visible.

Security matters because users trust you with their data, and catching vulnerabilities early is much cheaper than dealing with them post-launch. Building secure apps also improves client confidence, can reduce emergency patches during late hours, and makes for a more stable development process. However, no app is completely unhackable, so the aim is to make it significantly more difficult for attackers.

Here are 10 practical ways to harden your Next.js app:

1. **Keep Next.js and dependencies updated:** Security patches for frameworks are frequently released. For instance, in 2025, a vulnerability (CVE-2025-29927) was found that allowed bypassing authorization in certain versions. Regularly update Next.js, React, and all dependencies, and check for security announcements.

2. **Check permissions close to the data:** Instead of relying solely on middleware or hidden controls, validate permissions directly where data is accessed or modified. Use server actions and route handlers like public API endpoints. Perform login checks, input validation, and ownership verification on the server side to prevent unauthorized actions.

3. **Validate every input on the server:** Browser-based validation is for user experience, not security. Any request can bypass client-side checks. Always validate request bodies, query parameters, and form data on the server using schema libraries like Zod. Reject unexpected inputs instead of attempting to fix them later.

4. **Add security headers:** Security headers can protect your app by closing multiple doors at once. In Next.js, set headers such as `X-Content-Type-Options`, `X-Frame-Options`, `Referrer-Policy`, `Strict-Transport-Security`, and `Permissions-Policy` in `next.config.ts`. For a Content Security Policy (CSP), use nonces carefully to balance security with functionality. Refer to the Next.js documentation for proper setup.

5. **Protect cookies and sessions:** If you manage sessions manually, ensure cookies are set with `httpOnly` to prevent client-side access, `secure` to enforce HTTPS usage, and `sameSite` to limit cross-site request forgery risks. Always regenerate session IDs after sensitive operations and implement proper session expiration and invalidation strategies.

By implementing these practices, you significantly reduce the risk of breaches and vulnerabilities in your Next.js applications, providing a safer environment for usersโ€™ sensitive information.

Written by urgent.news from Dev.to's reporting โ€” not their text. Machine-written โ€” may contain errors; check the original before relying on it.

Read the original at dev.to โ†’

More in Tech

Episode zero first, the rest of setup after

a new underway account now opens on one card. it says episode 0, it asks for your first name and one line about what you are documenting, and it has one gold button: start episode zero.

  • Episode Zero is the new starting point of the setup process
  • Users provide first name and one-line description after Episode Zero
  • Simplified setup with fewer screens improves user navigation

A green diff is not a completeness check

Every agent-authored change arrives with the same reassuring signal: the tests pass, the diff is small, nothing looks obviously wrong.

  • A single software change may have unnoticed impacts despite passing tests.
  • Deletion can be consistent with all test assertions, appearing harmless.
  • Separate diff showing surface changes aids completeness assessment.

You Can Now Accept or Decline DEV Organization Invitations From Notifications! ๐ŸŽ‰

A small but useful improvement to DEV that I'm happy to share! I came across an issue raised by @francistrdev about accepting or declining organization invitations directly from the notificationsโ€ฆ

  • Users can accept or decline DEV organization invitations via notifications.
  • Notifications display "Accept" and "Decline" options for invitations.
  • Feature enhancements involved multiple components and recent contributions.

Serv-U's Critical CVE Cluster Is an Authorization and Patching Problem

Serv-U's Critical CVE Cluster Is an Authorization and Patching Problem SolarWinds Serv-U 2026.3 release notes list a cluster of critical vulnerabilities fixed in the July 21, 2026 release.

  • Critical vulnerabilities rated 9.1 severity allow privilege escalation
  • Majority of issues impact Linux deployments, risking root-level execution
  • Upgrade to patched release, enforce privilege separation and logging

Why your CSS gradient looks muddy in the middle (and the one-line fix)

If you've ever written linear-gradient(blue, yellow) and got a dull grey-ish band in the middle, the colours aren't wrong; the interpolation is.

  • CSS gradients appear muddy in middle due to sRGB color space blending
  • Interpolate colors in perceptually even color spaces like OKLab or OKLCH
  • OKLab recommended for most UI gradients, OKLCH for vivid backgrounds

More from Saturday 14 November โ†’