René's URL Explorer Experiment


Title: Prototype Inheritance Bug — Shared Array Leaks Tenant Data

Open Graph Title: Prototype Inheritance Bug — Shared Array Leaks Tenant Data

Description: A shared array on a prototype caused cross-tenant data leakage. Avoid this by never mutating shared prototypes. Production lessons from real incidents.

Open Graph Description: A shared array on a prototype caused cross-tenant data leakage. Avoid this by never mutating shared prototypes. Production lessons from real incidents.

Opengraph URL: https://thecodeforge.io/javascript/prototypes-inheritance-javascript/

direct link

Domain: thecodeforge.io


Hey, it has json ld scripts:
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://thecodeforge.io/javascript/prototypes-inheritance-javascript/"
  },
  "headline": "Prototype Inheritance Bug — Shared Array Leaks Tenant Data",
  "description": "A shared array on a prototype caused cross-tenant data leakage. Avoid this by never mutating shared prototypes. Production lessons from real incidents.",
  "keywords": "Prototype Inheritance Bug — Shared Array Leaks Tenant Data, JavaScript, Intermediate, Advanced JS, A shared array on a prototype caused cross-tenant data leakage. Avoid this by never mutating shared prototypes. Production lessons from real incidents.",
  "proficiencyLevel": "Intermediate",
  "author": {
    "@type": "Person",
    "@id": "https://thecodeforge.io/about/#naren",
    "name": "Naren",
    "url": "https://thecodeforge.io/about/"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://thecodeforge.io/#org",
    "name": "TheCodeForge",
    "url": "https://thecodeforge.io",
    "logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
  },
  "datePublished": "2026-03-05T00:00:00+00:00",
  "dateModified": "2026-08-30T00:00:00+00:00",
  "url": "https://thecodeforge.io/javascript/prototypes-inheritance-javascript/",
  "inLanguage": "en",
  "educationalLevel": "Intermediate",
  "image": "https://thecodeforge.io/assets/og-image.png",
  "isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
    {"@type": "ListItem", "position": 2, "name": "JavaScript", "item": "https://thecodeforge.io/javascript/"},
    {"@type": "ListItem", "position": 3, "name": "Prototype Inheritance Bug — Shared Array Leaks Tenant Data", "item": "https://thecodeforge.io/javascript/prototypes-inheritance-javascript/"}
  ]
}
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "What is the prototype chain in JavaScript?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "The prototype chain is the mechanism JavaScript uses to look up properties and methods. Every object has a hidden [[Prototype]] link to another object. When you access a property, JS first checks the object itself, then walks up the chain through each linked object until it either finds the property or reaches null at the end of the chain."
      }
    },
    {
      "@type": "Question",
      "name": "What is the difference between classical inheritance and prototypal inheritance?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Classical inheritance (Java, C++) copies a blueprint — the class — into new instances at compile time. Prototypal inheritance (JavaScript) links objects together at runtime. Instances don't copy methods; they delegate to their prototype. This means you can modify the prototype after instances are created and all instances immediately see the change."
      }
    },
    {
      "@type": "Question",
      "name": "Does using ES6 classes mean JavaScript is no longer prototype-based?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "No. ES6 classes are syntax on top of the same prototype system. Running class Dog extends Animal creates a constructor function and wires Dog.prototype to Animal.prototype using Object.create() — exactly as you'd do manually. You can verify this by checking Object.getPrototypeOf(Dog.prototype) === Animal.prototype, which returns true for any class hierarchy."
      }
    },
    {
      "@type": "Question",
      "name": "What is the best way to inspect an object's prototype chain?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Use Object.getPrototypeOf() in a loop until null. Or in browser DevTools, console.dir(obj) shows the full chain. Avoid __proto__ in production code."
      }
    },
    {
      "@type": "Question",
      "name": "How do I prevent prototype pollution in my application?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Use Object.create(null) for objects that serve as maps, always filter __proto__ and constructor keys when merging user input, freeze Object.prototype in critical environments, and use libraries with built-in pollution prevention (e.g., lodash's cloneDeep has patches but still sanitize yourself)."
      }
    },
    {
      "@type": "Question",
      "name": "Does for..in loop over inherited properties?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Yes — for..in iterates all enumerable properties, including inherited ones from the prototype chain. This is a frequent source of bugs when you add methods to a shared prototype and then iterate object instances. Use Object.keys(obj) for own-only enumerable properties, or guard with if (Object.hasOwn(obj, key)) inside the loop. Object.hasOwn() is the modern replacement for the older obj.hasOwnProperty(key)."
      }
    },
    {
      "@type": "Question",
      "name": "What is the difference between __proto__ and prototype?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "__proto__ is the actual link between an object instance and its prototype — it's the [[Prototype]] internal slot exposed as a property. prototype is a property on constructor functions that becomes the [[Prototype]] of objects created with new. When you write new Foo(), the resulting object's __proto__ is set to Foo.prototype. They're two sides of the same chain: prototype defines it, __proto__ accesses it."
      }
    },
    {
      "@type": "Question",
      "name": "Why does this lose its value when you extract a prototype method?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Because this is determined by the call site, not by where the method is defined. When you write const fn = obj.method and then call fn(), there is no object before the dot — so this becomes undefined in strict mode (or the global object in sloppy mode). The method travels without its context. Fix it with const fn = obj.method.bind(obj) to permanently attach obj as this, or use an arrow function wrapper: const fn = () => obj.method()."
      }
    },
    {
      "@type": "Question",
      "name": "What is the SmooshGate incident and what does it prove about monkey patching?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "In 2018, TC39 proposed Array.prototype.flatten(). It turned out MooTools (a library from 2006 still running on millions of sites) had already added Array.prototype.flatten with different semantics. Browsers couldn't implement the new flatten without breaking those sites. The proposal had to be renamed to Array.prototype.flat(). The lesson: the moment you patch a built-in prototype, you've made a global contract that is nearly impossible to revoke. Never patch built-ins — use standalone utility functions instead."
      }
    }
  ]
}

og:typewebsite
og:imagehttps://thecodeforge.io/assets/og-image.png
og:image:width1200
og:image:height630

Links:

TheCodeForge https://thecodeforge.io/
JavaScripthttps://thecodeforge.io/javascript/
Buy me a coffee https://ko-fi.com/thecodeforge
1Closures in JavaScripthttps://thecodeforge.io/javascript/closures-javascript/
2Promises in JavaScripthttps://thecodeforge.io/javascript/promises-javascript/
3async and await in JavaScripthttps://thecodeforge.io/javascript/async-await-javascript/
4Event Loop in JavaScripthttps://thecodeforge.io/javascript/event-loop-javascript/
5Prototypes and Inheritance in JShttps://thecodeforge.io/javascript/prototypes-inheritance-javascript/
6ES6+ Features in JavaScripthttps://thecodeforge.io/javascript/es6-features-javascript/
7Destructuring in JavaScripthttps://thecodeforge.io/javascript/destructuring-javascript/
8Spread and Rest Operatorshttps://thecodeforge.io/javascript/spread-rest-operators-javascript/
9Arrow Functions in JavaScripthttps://thecodeforge.io/javascript/arrow-functions-javascript/
10Modules in JavaScript — import exporthttps://thecodeforge.io/javascript/modules-javascript/
11Symbol and BigInt in JavaScripthttps://thecodeforge.io/javascript/symbol-bigint-javascript/
12WeakMap and WeakSet in JavaScripthttps://thecodeforge.io/javascript/weakmap-weakset-javascript/
13Generators in JavaScripthttps://thecodeforge.io/javascript/generators-javascript/
14Proxy and Reflect in JavaScripthttps://thecodeforge.io/javascript/proxy-reflect-javascript/
15Currying in JavaScripthttps://thecodeforge.io/javascript/currying-javascript/
16Memoisation in JavaScripthttps://thecodeforge.io/javascript/memoisation-javascript/
17Design Patterns in JavaScripthttps://thecodeforge.io/javascript/design-patterns-javascript/
18Functional Programming in JShttps://thecodeforge.io/javascript/functional-programming-javascript/
19Web Workers in JavaScripthttps://thecodeforge.io/javascript/web-workers-javascript/
20Observables and RxJShttps://thecodeforge.io/javascript/observables-rxjs/
21WebMCP — AI Tool Integration for the Webhttps://thecodeforge.io/javascript/webmcp-ai-tool-integration/
22Introduction to Angular: Components, Modules and Serviceshttps://thecodeforge.io/javascript/introduction-to-angular/
23Angular Expansion Panel: Building Accordions with Materialhttps://thecodeforge.io/javascript/angular-expansion-panel/
24Frontend Frameworks Compared: React vs Angular vs Vue in 2026https://thecodeforge.io/javascript/frontend-frameworks-overview/
25Cursor AI Mastery: How to 10X Your Development Speed in 2026https://thecodeforge.io/javascript/cursor-ai-mastery-10x-development-speed/
26Cursor vs Windsurf vs GitHub Copilot — Real Developer Test 2026https://thecodeforge.io/javascript/cursor-vs-windsurf-vs-copilot/
27TensorFlow.js for JavaScript Developers – Machine Learning in Browserhttps://thecodeforge.io/javascript/tensorflowjs-machine-learning-javascript/
28CORS Policy Error Fixhttps://thecodeforge.io/javascript/cors-policy-error/
← Back to JavaScript track https://thecodeforge.io/javascript/
Homehttps://thecodeforge.io/
JavaScripthttps://thecodeforge.io/javascript/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
 ● Production Incidenthttps://thecodeforge.io/javascript/prototypes-inheritance-javascript/#v2-production-incident
 🔎 Debug Guidehttps://thecodeforge.io/javascript/prototypes-inheritance-javascript/#v2-debug-guide
 ⚙ Triage Commandshttps://thecodeforge.io/javascript/prototypes-inheritance-javascript/#v2-triage-commands
JavaScripthttps://thecodeforge.io/javascript/introduction-javascript/
inheritancehttps://thecodeforge.io/java/inheritance-java/
Array methodshttps://thecodeforge.io/javascript/array-methods-javascript/
arrayhttps://thecodeforge.io/dsa/array-data-structure/
designhttps://thecodeforge.io/javascript/design-patterns-javascript/
functionshttps://thecodeforge.io/javascript/functions-javascript/
Try it livehttps://codepen.io/pen/?editors=1000
stackhttps://thecodeforge.io/dsa/stack-data-structure/
Try it livehttps://codepen.io/pen/?editors=1000
Stringshttps://thecodeforge.io/c-cpp/strings-c/
dictionarieshttps://thecodeforge.io/python/dictionaries-python/
Try it livehttps://codepen.io/pen/?editors=1000
serializationhttps://thecodeforge.io/java/serialization-java/
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
strict modehttps://thecodeforge.io/javascript/strict-mode-typescript/
Arrow functionshttps://thecodeforge.io/javascript/arrow-functions-javascript/
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
Try it livehttps://codepen.io/pen/?editors=1000
→JS Objects - Silent Mutation Broke User SessionsObject mutation from reference copy in JavaScript corrupted user sessions: changing one user's email altered others. Fixhttps://thecodeforge.io/javascript/objects-javascript/
→JS Design Patterns — Singleton State Leaks in TestsTests pass alone but fail together? Singleton mutations persist across Node.js test files. Fix state isolation and avoidhttps://thecodeforge.io/javascript/design-patterns-javascript/
→JavaScript Closures — Silent Memory Leak from DOM NodesRSS memory grew for 6h until OOMKill — closures captured jsdom DOM nodes. Heap snapshots show detached DOM trees. Real ihttps://thecodeforge.io/interview/javascript-closures-interview-questions/
→Closure Memory Leaks — Top JS Interview QuestionsHeap usage grows monotonically — closures in Express route handlers retaining req objects cause OOM. Avoid this in interhttps://thecodeforge.io/interview/top-javascript-interview-questions/
→ES6+ Features Explained — The Why, When, and Real-World HowES6+ JavaScript features demystified — learn arrow functions, destructuring, async/await, and more with real-world pattehttps://thecodeforge.io/javascript/es6-features-javascript/
WordPress White Screen of Death — Isolate the PluginBeginnerhttps://thecodeforge.io/web-platform/wordpress-white-screen-of-death/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
←PreviousEvent Loop in JavaScripthttps://thecodeforge.io/javascript/event-loop-javascript/
NextES6+ Features in JavaScript→https://thecodeforge.io/javascript/es6-features-javascript/
LinkedIn https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
Facebook https://www.facebook.com/profile.php?id=61583020033815
YouTube https://www.youtube.com/channel/UCMar7CF2EmCF1I2tw1tNVuQ
Javahttps://thecodeforge.io/java/
Pythonhttps://thecodeforge.io/python/
C / C++https://thecodeforge.io/c-cpp/
JavaScripthttps://thecodeforge.io/javascript/
DSAhttps://thecodeforge.io/dsa/
Databasehttps://thecodeforge.io/database/
System Designhttps://thecodeforge.io/system-design/
DevOpshttps://thecodeforge.io/devops/
C# / .NEThttps://thecodeforge.io/csharp/
PHPhttps://thecodeforge.io/php/
ML / AIhttps://thecodeforge.io/ml-ai/
Interviewhttps://thecodeforge.io/interview/
CS Fundamentalshttps://thecodeforge.io/cs-fundamentals/
Rusthttps://thecodeforge.io/rust/
Toolshttps://thecodeforge.io/tools/
Cheatsheetshttps://thecodeforge.io/cheatsheets/
Mobilehttps://thecodeforge.io/mobile/
Data Analyticshttps://thecodeforge.io/data-analytics/
Securityhttps://thecodeforge.io/security/
Frontendhttps://thecodeforge.io/frontend/
Data Engineeringhttps://thecodeforge.io/data-engineering/
Testinghttps://thecodeforge.io/testing/
Cloudhttps://thecodeforge.io/cloud/
Observabilityhttps://thecodeforge.io/observability/
Web Platformhttps://thecodeforge.io/web-platform/
🧯 Errors Explainedhttps://thecodeforge.io/errors/
⚒ Blueprintshttps://thecodeforge.io/blueprints/
⌨ Practicehttps://thecodeforge.io/practice/
Interview Prephttps://thecodeforge.io/interview/
DSA Problemshttps://thecodeforge.io/dsa/
Developer Toolshttps://thecodeforge.io/tools/
Cheat Sheetshttps://thecodeforge.io/cheatsheets/
Abouthttps://thecodeforge.io/about/
Sitemaphttps://thecodeforge.io/sitemap.xml
Privacyhttps://thecodeforge.io/privacy.html

Viewport: width=device-width, initial-scale=1.0

Robots: max-image-preview:large


URLs of crawlers that visited me.