Back to blog

Critical Vulnerability in React and Next.js Allows Remote Code Execution

Hello HaWkers, one of the most severe vulnerabilities in React ecosystem history has been discovered and is already being actively exploited. CVE-2025-55182, nicknamed "React2shell", received the maximum CVSS score of 10.0 and affects millions of applications in production.

If you use React Server Components or Next.js, this article could save your application from a devastating attack.

What Is the React2shell Vulnerability

The flaw exists in how React decodes payloads sent to React Server Functions endpoints. An unauthenticated attacker can exploit this vulnerability to execute arbitrary code on the server.

Technical details of CVE-2025-55182:

  • CVSS Score: 10.0 (Critical)
  • Attack Vector: Network
  • Complexity: Low
  • Privileges Required: None
  • User Interaction: Not required

🔥 Alert: This vulnerability allows remote code execution (RCE) without any authentication. Attackers can take complete control of the server.

Affected and Fixed Versions

The vulnerability affects several React versions. Here is the current status:

React

Version Status Required Action
< 19.0.1 Vulnerable Update immediately
19.0.1 Fixed Safe
19.1.x < 19.1.2 Vulnerable Update to 19.1.2
19.1.2 Fixed Safe
19.2.x < 19.2.1 Vulnerable Update to 19.2.1
19.2.1 Fixed Safe

Next.js

All versions using React Server Components with vulnerable React versions are at risk. Update React and verify Next.js is using the fixed version.

How the Exploit Works

Without going into details that could facilitate attacks, the vulnerability exploits a flaw in data deserialization in Server Functions.

Simplified attack flow:

  1. Attacker identifies Server Function endpoint
  2. Sends specially formatted malicious payload
  3. React deserializes the payload insecurely
  4. Arbitrary code is executed on the server
  5. Attacker gains system access

Indicators of Compromise

Watch for these signs in your logs:

  • Unusual requests to Server Actions endpoints
  • Payloads with special characters or unusual encoding
  • Unexpected child processes on the server
  • Unauthorized network connections originating from the server

How to Protect Your Application

Follow these steps immediately to protect your applications:

Step 1: Check React Version

# In your project, check the version
npm list react

# Or with yarn
yarn list react

Step 2: Update to Fixed Version

# Update React to safe version
npm update react react-dom

# Or specify exact version
npm install react@19.2.1 react-dom@19.2.1

Step 3: Check Dependencies

# Check for known vulnerabilities
npm audit

# Auto-fix if possible
npm audit fix

Step 4: Implement Additional Security Layers

Even after updating, consider these additional measures:

// middleware.js - Example of additional validation
export function middleware(request) {
  // Validate Content-Type for Server Actions
  if (request.method === 'POST') {
    const contentType = request.headers.get('content-type');

    // Server Actions use multipart/form-data or application/x-www-form-urlencoded
    const allowedTypes = [
      'multipart/form-data',
      'application/x-www-form-urlencoded'
    ];

    const isAllowed = allowedTypes.some(type =>
      contentType?.includes(type)
    );

    if (!isAllowed) {
      return new Response('Invalid Content-Type', { status: 400 });
    }
  }

  return NextResponse.next();
}

Step 5: Monitor Logs

Implement monitoring to detect exploitation attempts:

// Example logging for Server Actions
export async function myServerAction(formData) {
  // Audit log
  console.log({
    timestamp: new Date().toISOString(),
    action: 'myServerAction',
    ip: headers().get('x-forwarded-for'),
    userAgent: headers().get('user-agent'),
    payloadSize: formData.toString().length
  });

  // Validate input rigorously
  const input = formData.get('input');
  if (typeof input !== 'string' || input.length > 1000) {
    throw new Error('Invalid input');
  }

  // Continue with normal logic
}

Security Lessons For Developers

This vulnerability teaches us important lessons about security in modern applications:

1. Server Components Are Not Magically Secure

The fact that code runs on the server does not mean it is protected. Any user input should be treated with distrust.

2. Security Updates Are Critical

Keeping dependencies updated is not optional. Set up automatic alerts for vulnerabilities in your dependencies.

3. Defense in Depth

Never rely on a single security layer. Implement validation at multiple levels.

4. Proactive Monitoring

Detecting ongoing attacks can be as important as preventing them.

Useful Security Tools

To detect vulnerabilities:

  • npm audit / yarn audit
  • Snyk
  • GitHub Dependabot
  • OWASP Dependency-Check

For monitoring:

  • Sentry
  • DataDog
  • New Relic
  • Elastic APM

Impact on React Ecosystem

This vulnerability has broad implications for the ecosystem:

For companies:

  • Urgent security audits
  • Review of all React applications in production
  • Possible regulatory impact (GDPR, CCPA)

For developers:

  • Need for security knowledge
  • Importance of security-focused code review
  • Value of automated security testing

Conclusion and Next Steps

The React2shell vulnerability is a serious reminder that security must be a priority in any project. Do not delay updating your applications.

Immediate checklist:

  • Check React version in all projects
  • Update to fixed versions
  • Run npm audit
  • Review logs for suspicious activity
  • Implement monitoring if not existing

If you want to learn more about security in modern JavaScript applications, I recommend checking out the article about MongoDB: Critical Vulnerability Exposes 87 Thousand Servers where you will discover how to protect your applications from other critical threats.

Let's go! 🦅

💻 Master JavaScript for Real

The knowledge you gained in this article is just the beginning. There are techniques, patterns, and practices that transform beginner developers into sought-after professionals.

Invest in Your Future

I have prepared complete material for you to master JavaScript:

Payment options:

  • 1x of $4.90 no interest
  • or $4.90 at sight

📖 View Complete Content

Comments (0)

This article has no comments yet 😢. Be the first! 🚀🦅

Add comments