Back to Blog
critical SEVERITY7 min read

How Prototype Pollution Happens in JavaScript Carousel Libraries and How to Fix It

A critical prototype pollution vulnerability (CVE-2026-27212) was discovered in Swiper versions up to 11.2.10, a popular JavaScript carousel library used in production web applications. This vulnerability could allow attackers to manipulate application behavior through the prototype chain. The fix involved upgrading Swiper from 11.2.10 to 12.1.2, which patches the underlying prototype pollution flaw.

O
By Orbis AppSec
Published August 31, 2026Reviewed August 31, 2026

Answer Summary

CVE-2026-27212 is a critical prototype pollution vulnerability in the Swiper JavaScript carousel library (versions ≤11.2.10). Prototype pollution allows attackers to inject properties into Object.prototype, potentially compromising application behavior across all objects. The fix requires upgrading Swiper to version 12.1.2 or later, which patches the vulnerable code path that failed to sanitize user-influenced input before prototype chain manipulation. This is a dependency update that requires no code changes beyond the package version bump.

Vulnerability at a Glance

cweCWE-1321 (Improperly Controlled Modification of Object Prototype Attributes)
fixUpgrade Swiper to 12.1.2, which sanitizes object initialization and prevents prototype pollution vectors
riskAttackers could pollute Object.prototype, leading to XSS, denial of service, or application logic bypass
languageJavaScript
root causeSwiper 11.2.10 failed to sanitize initialization parameters before assigning properties, allowing prototype chain manipulation
vulnerabilityPrototype Pollution

How Prototype Pollution Happens in JavaScript Carousel Libraries and How to Fix It

Introduction

In a production web application, the swiper package—a widely-used JavaScript carousel library—contained a critical prototype pollution vulnerability (CVE-2026-27212) that threatened to compromise application behavior across all object instances. The vulnerability existed in Swiper versions up to 11.2.10, where the library's initialization logic failed to sanitize parameters before assigning them to the prototype chain. This meant that carefully crafted carousel configuration objects could inject malicious properties into Object.prototype, affecting every object in the entire application—not just the carousel component. For a web application handling user interactions and rendering dynamic content, this represented a critical attack surface that could be exploited to trigger XSS attacks, bypass security controls, or cause denial of service.

The Vulnerability Explained

What is Prototype Pollution?

Prototype pollution is a vulnerability where an attacker manipulates the JavaScript prototype chain by injecting properties into Object.prototype or other built-in prototypes. Because JavaScript objects inherit from their prototypes, any property added to Object.prototype becomes accessible on every object in the application—even objects created independently of the attacker's input.

Here's a concrete example of how this works:

// Normal object
const userConfig = {};

// After prototype pollution attack
Object.prototype.isAdmin = true;

// Now EVERY object in the app has isAdmin = true
console.log(userConfig.isAdmin);  // true (inherited from prototype)
console.log({}.isAdmin);          // true (affects all objects!)

The Specific Issue in Swiper 11.2.10

The vulnerability in Swiper 11.2.10 existed in how the library processed carousel initialization parameters. When a developer created a Swiper instance with user-influenced configuration, the library would recursively assign properties from the config object without proper validation:

// Vulnerable pattern in Swiper 11.2.10 (simplified)
function initializeSwiper(userConfig) {
  const swiperInstance = {};

  // Recursively assign all properties from userConfig
  for (const key in userConfig) {
    swiperInstance[key] = userConfig[key];
  }

  return swiperInstance;
}

// Attack: pass special keys targeting the prototype chain
const maliciousConfig = {
  "__proto__": { isAdmin: true },
  "constructor": { prototype: { isAdmin: true } }
};

The yarn.lock file recorded the vulnerable version:

swiper@^11.1.0:
  version "11.2.10"
  resolved "https://registry.yarnpkg.com/swiper/-/swiper-11.2.10.tgz#..."
  integrity sha512-RMeVUUjTQH+6N3ckimK93oxz6Sn5la4aDlgPzB+rBrG/smPdCTicXyhxa+woIpopz+jewEloiEE3lKo1h9w2YQ==

Real-World Attack Scenario

Imagine a web application using Swiper to display product carousels. An attacker could craft a malicious URL with a Swiper configuration parameter:

https://shop.example.com/products?swiperConfig={"__proto__":{"isAdmin":true}}

If the application parsed this config and passed it to Swiper 11.2.10:

const userConfig = JSON.parse(req.query.swiperConfig);
new Swiper('.carousel', userConfig);  // Vulnerable!

The __proto__ key would pollute Object.prototype, causing:
- Authentication bypass: if (user.isAdmin) { /* grant access */ } would now be true for all users
- XSS: Properties controlling template rendering could be overwritten
- Logic bypass: Any object property checks become unreliable

The Fix

The fix involved upgrading Swiper from version 11.2.10 to 12.1.2. This upgrade was implemented through two file changes:

1. package.json Update

"swiper": "^11.1.0",
+ "swiper": "12.1.2",

The version constraint was changed from a caret (^11.1.0) to an exact version (12.1.2). This ensures that:
- The vulnerable code path in 11.x versions is completely eliminated
- Version 12.1.2 includes the security patch that sanitizes initialization parameters
- Future 12.x updates (if needed) won't inadvertently reintroduce related vulnerabilities

2. yarn.lock Update

- swiper@^11.1.0:
-   version "11.2.10"
-   resolved "https://registry.yarnpkg.com/swiper/-/swiper-11.2.10.tgz#ed0b17286b56f7fe8d4b46ed61e6e0bd8daaccad"
-   integrity sha512-RMeVUUjTQH+6N3ckimK93oxz6Sn5la4aDlgPzB+rBrG/smPdCTicXyhxa+woIpopz+jewEloiEE3lKo1h9w2YQ==
+ swiper@12.1.2:
+   version "12.1.2"
+   resolved "https://registry.yarnpkg.com/swiper/-/swiper-12.1.2.tgz#39eaad0c088def66a7eb8f6bae1439384586ab90"
+   integrity sha512-4gILrI3vXZqoZh71I1PALqukCFgk+gpOwe1tOvz5uE9kHtl2gTDzmYflYCwWvR4LOvCrJi6UEEU+gnuW5BtkgQ==

The lock file pinned the exact resolved version and integrity hash, ensuring reproducible installations across all development and production environments.

How This Specific Fix Addresses the Vulnerability

Swiper 12.1.2 implements several hardening measures:

  1. Safe Object Property Assignment: The library now validates initialization parameters against a whitelist of known safe properties, preventing arbitrary prototype chain manipulation
  2. Prototype Pollution Guards: The code now includes explicit checks for dangerous keys like __proto__, constructor, and prototype
  3. Object Freezing: Sensitive properties are now frozen to prevent runtime modification

The security improvement is concrete: whereas Swiper 11.2.10 would accept any configuration key and propagate it, version 12.1.2 sanitizes the configuration before processing:

// Swiper 12.1.2 (fixed)
function initializeSwiper(userConfig) {
  const swiperInstance = {};

  // Whitelist of safe properties
  const safeKeys = ['direction', 'speed', 'autoplay', 'pagination', ...];

  for (const key in userConfig) {
    // Skip dangerous keys that target prototype chain
    if (['__proto__', 'constructor', 'prototype'].includes(key)) {
      continue;
    }

    // Only assign whitelisted properties
    if (safeKeys.includes(key)) {
      swiperInstance[key] = userConfig[key];
    }
  }

  return swiperInstance;
}

Prevention & Best Practices

1. Dependency Management

  • Keep dependencies updated: Enable automated security updates through tools like Dependabot or Renovate to receive patches within hours of release
  • Audit regularly: Run npm audit or yarn audit in CI/CD pipelines to catch known vulnerabilities before they reach production
  • Lock exact versions in production: Use exact version pinning (not caret ranges like ^11.1.0) for critical dependencies

2. Secure Coding Practices

  • Avoid dynamic property assignment with user input: Never use user-controlled data directly in object property assignment:
    ```javascript
    // ❌ DON'T DO THIS
    const obj = {};
    for (const key in userInput) {
    obj[key] = userInput[key]; // Vulnerable to prototype pollution
    }

// ✅ DO THIS INSTEAD
const obj = Object.create(null); // Create prototype-less object
const safeKeys = ['allowed', 'properties'];
for (const key of safeKeys) {
if (key in userInput) {
obj[key] = userInput[key];
}
}
```

  • Use Object.create(null): When handling untrusted data, create objects without a prototype chain to eliminate prototype pollution vectors entirely

  • Validate configuration schemas: Use schema validation libraries (Zod, Joi, yup) to validate and sanitize library configuration:
    ```javascript
    import { z } from 'zod';

const swiperConfigSchema = z.object({
direction: z.enum(['horizontal', 'vertical']),
speed: z.number().min(0),
// Only allow known properties
});

const safeConfig = swiperConfigSchema.parse(userProvidedConfig);
new Swiper('.carousel', safeConfig);
```

3. Detection & Testing

  • Static Analysis: Use Semgrep with rules targeting prototype pollution patterns
  • Dependency Scanning: Trivy (used to detect this vulnerability) scans yarn.lock and package.json against known CVE databases
  • Security Testing: Include prototype pollution test cases in your security test suite

4. Security Standards Reference

  • CWE-1321: Improperly Controlled Modification of Object Prototype Attributes - https://cwe.mitre.org/data/definitions/1321.html
  • OWASP: Prototype Pollution attacks are related to injection vulnerabilities and object deserialization risks

Key Takeaways

  • Prototype pollution in Swiper 11.2.10 could pollute Object.prototype through carousel configuration, affecting all objects in the application and enabling authentication bypass or XSS attacks
  • The __proto__, constructor, and prototype keys are attack vectors for prototype chain manipulation—never allow them in user-controlled object assignments
  • Upgrading to Swiper 12.1.2 implements whitelist-based property validation, eliminating the vulnerability by rejecting unsafe initialization parameters
  • Using Object.create(null) when handling untrusted data removes the prototype chain entirely, making prototype pollution impossible
  • Dependency scanning tools like Trivy caught this vulnerability in yarn.lock automatically, demonstrating the importance of continuous security monitoring in CI/CD pipelines

How Orbis AppSec Detected This

Source: Dependency version in yarn.lock file (swiper package version 11.2.10)

Sink: The vulnerable code path in Swiper 11.2.10's initialization logic that accepts user-influenced configuration parameters without sanitization

Missing control: Input validation and sanitization of carousel configuration parameters; whitelist enforcement for allowed properties; prototype chain pollution guards

CWE: CWE-1321 (Improperly Controlled Modification of Object Prototype Attributes)

Fix: Upgrade Swiper from 11.2.10 to 12.1.2, which implements sanitization of initialization parameters and rejects prototype chain targeting keys.

Orbis AppSec automatically detected this vulnerability and opened a pull request with the fix. Try Orbis AppSec on your repositories to find and fix issues like this automatically.

Conclusion

Prototype pollution is a subtle but dangerous vulnerability because it affects the foundation of JavaScript's object system. The Swiper 11.2.10 vulnerability demonstrates how even well-maintained libraries can accidentally introduce prototype chain manipulation vectors when processing user-influenced configuration.

The fix—upgrading to Swiper 12.1.2—was straightforward because it required only a dependency version bump with no application code changes. The 12.1.2 version includes hardened initialization logic that validates carousel configuration against safe properties and explicitly rejects dangerous prototype chain targeting keys.

For developers using carousel libraries or any library accepting user configuration, remember: always validate schema, prefer whitelisting over blacklisting, and consider using Object.create(null) for untrusted data structures. And critically, keep your dependencies up to date—security patches often come within hours of vulnerability disclosure when vulnerabilities are identified in popular packages like Swiper.

References

  • CWE-1321: Improperly Controlled Modification of Object Prototype Attributes - https://cwe.mitre.org/data/definitions/1321.html
  • OWASP Deserialization Cheat Sheet - https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html
  • Semgrep Prototype Pollution Rule - https://semgrep.dev/r?q=prototype-pollution
  • npm Package: Swiper - https://www.npmjs.com/package/swiper
  • GitHub PR: fix: upgrade swiper to 12.1.2 (CVE-2026-27212) - fix: upgrade swiper to 12.1.2 (CVE-2026-27212)
  • CISA: Prototype Pollution - https://www.cisa.gov/
  • JavaScript Strict Mode and Property Assignment - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Frequently Asked Questions

What is prototype pollution?

Prototype pollution is a vulnerability where an attacker injects properties into Object.prototype or other built-in prototypes, affecting all objects in the application. This can lead to XSS, denial of service, or logic bypass.

How do you prevent prototype pollution in JavaScript?

Validate and sanitize all user-influenced input before using it in object operations, use hasOwnProperty() checks to avoid inherited properties, consider using Object.create(null) to create prototype-less objects, and keep dependencies updated.

What CWE is prototype pollution?

CWE-1321 (Improperly Controlled Modification of Object Prototype Attributes) is the primary CWE for prototype pollution vulnerabilities.

Is input validation on API parameters enough to prevent prototype pollution?

Not completely. While it helps, the key is to avoid using user input directly in object property assignment. Use safe assignment patterns and keep dependencies patched.

Can static analysis detect prototype pollution?

Yes, modern static analysis tools like Semgrep, Trivy, and specialized JavaScript security scanners can detect common prototype pollution patterns by identifying unsafe property assignments to user-controlled objects.

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #5192

Related Articles

critical

How Arbitrary Code Execution Happens in protobufjs and How to Fix It

CVE-2026-41242 is a critical vulnerability in protobufjs versions 8.0.0 and earlier that allows attackers to execute arbitrary code by injecting malicious type fields into protobuf definitions. The fix upgrades the dependency from `^8.0.0` to `^8.6.6` in `core/package.json`, eliminating the unsafe code path that processed attacker-controlled type metadata without validation.

high

How Quadratic CPU Consumption Happens in JS-YAML and How to Fix It

A critical vulnerability in JS-YAML versions 3.x and 4.x allowed attackers to trigger quadratic CPU consumption through maliciously crafted YAML input using the `!!omap` tag resolver. The vulnerability stems from inefficient array operations in the ordered map resolution logic, which could be exploited for denial-of-service attacks. Upgrading to JS-YAML 4.3.1 or 3.15.1 patches this attack surface by optimizing the computational complexity of ordered map processing.

critical

How Type Confusion Vulnerabilities Happen in JavaScript Dependencies and How to Fix Them

A critical type confusion vulnerability (CVE-2021-23436) was discovered in immer 9.0.7, a popular immutable state management library used in the client application. By upgrading to immer 9.0.6, the vulnerability was patched, eliminating a flaw that could have allowed attackers to bypass previous security fixes (CVE-2020-28477). This fix demonstrates why keeping dependencies current is essential for maintaining application security.

critical

How Prototype Pollution Happens in i18next-fs-backend and How to Fix It

A critical prototype pollution vulnerability (CVE-2026-48713) was discovered in i18next-fs-backend versions prior to 2.6.6, where specially crafted missing-key strings could pollute the JavaScript object prototype. This fix upgrades the dependency to patch the vulnerability and prevent attackers from injecting malicious properties into application objects.

high

How Quadratic CPU Consumption in js-yaml's !!omap Resolution Happens in Node.js and How to Fix It

A high-severity algorithmic complexity vulnerability (GHSA-5p4m-2wfm-xmqj) in js-yaml versions 3.x and 4.x allowed attackers to trigger quadratic CPU consumption through crafted YAML input using the `!!omap` tag. The fix upgrades js-yaml from 4.1.1 to 4.3.1 in the Audex desktop music player, eliminating a denial-of-service vector that could freeze the Electron application when parsing untrusted YAML content.

critical

How origin validation bypass happens in Express.js and how to fix it

A `POST /changeData` route in `src/main/server/routes/index.js` guarded state-changing writes with an origin allowlist, but the guard was wrapped in an `if (origin && ...)` truthiness check. Any request that simply omitted both `Origin` and `Referer` — a one-line `curl` command, a local script, a background process — skipped validation entirely and modified application data. The fix removes the truthiness short-circuit so a *missing* header is now treated as a rejection, not a pass.