Questions
24 of 32
1What is the constructor function?
2What are Objects?
3What are the properties of an object?
4How does javascript implements object oriented programming?
5What are the key differences between javascript’s Object-based Inheritance and Conventional Class-based Inheritance?
6What is a prototype in JavaScript?
7How we can implement prototype-based inheritance?
8Explain the prototype chain and its role in property lookup.
9What is the difference between an object's `__proto__` and a constructor function's `prototype` property and [[Prototype]]?
10What are object wrappers for primitive type?
11Can you explain the use of object wrappers with examples?
12Explain how the `instanceof` operator works.
13What are different methods to create an object?
14What is an object initializer?
15What does the `Object.create()` method do?
16How are constructor functions used to create objects with shared properties and methods?
17Show an example of ES6 classes to create objects and inherit properties?
18What are factory functions in JavaScript ?
19What are Object constructors in JavaScript ?
20How can you add new properties and methods to the prototype of an existing constructor function?
21What is prototype pollution, and how can it be a security risk in JavaScript?
22Is modifying or extending built-in object prototypes recommended (e.g., adding a method to `Array.prototype`)? Why or why not?
23What happens when you try to access a property that doesn't exist on an object?
24How can you prevent or mitigate prototype pollution vulnerabilities in your code?
25How does the `Object.prototype.hasOwnProperty()` method work?
26How can you optimize prototype chain lookup for better performance?
27Can you explain how `Object.prototype.constructor` property works?
28What is the difference between modifying the prototype of an object and adding a property directly to the object?
29How does JavaScript handle circular references in object prototypes?
30What is static dispatching in object-oriented programming?
31What is the purpose of the `Object.keys()` method?
32Write a function flattenObject(obj) that flattens a deeply nested object into a single-level object, using dot notation for nested keys.
24 / 32

How can you prevent or mitigate prototype pollution vulnerabilities in your code?

To prevent prototype pollution, you should validate and sanitize any user input before using it to modify prototypes. Additionally, avoid using untrusted data to directly modify object prototypes, and use proper input validation techniques to prevent malicious input from causing unexpected behaviour.

Here is a breakdown of the most effective strategies to mitigate these risks.
  1. 1

    Use Object.create(null) : When creating an object to be used as a map or a data store, initialize it without a prototype. This makes it impossible for an attacker to traverse 'up' the chain to Object.prototype.

  2. 2

    Use Map instead of {}: The ES6 Map collection is inherently safer because it doesn't store data as properties on the object itself. It uses a separate internal mechanism, so even if someone pollutes Object.prototype, it won't appear in your Map.get() results.

  3. 3

    Always check for 'magic' keys that provide access to the prototype chain: proto, constructor, and prototype.

  4. 4

    Object.freeze(): You can freeze the base prototypes at the very start of your application (the entry point). Once frozen, no one—not even your own code—can add or modify properties on them.

  5. 5

    Never trust JSON data coming from a user. Use a schema validation library like Zod, Joi, or Ajv. These libraries ensure the object matches a specific shape and strip out any unexpected keys like proto.

  6. 6

    Static Analysis (Linting): Use ESLint plugins like eslint-plugin-security. They can flag dangerous patterns like obj[key] = value where key comes from user input.

  7. 7

    Dependency Auditing: Regularly run npm audit. Many prototype pollution vulnerabilities are found in popular npm packages (like lodash, extend, or dot-prop). If a vulnerability is found, update to the patched version immediately.

Difficulty: 7/10
Topics: object merging, input validation, secure libraries

Scenario Questions

0-2 years experience
  1. 1

    You need to merge user‑provided JSON into a config object using Object.assign. How would you ensure this doesn't introduce prototype pollution?

  2. 2

    If a third‑party library you use calls _.merge on an object you control, what check would you add before passing data to avoid polluting Object.prototype?

2-5 years experience
  1. 1

    During a bug‑hunt you notice that setting a property on a request payload unexpectedly adds a new method to all objects. Walk me through how you'd debug and fix the prototype pollution.

  2. 2

    Your team wants to use a deep‑merge utility for feature flags. What trade‑offs would you consider to prevent prototype pollution, and how would you test it?

5-8 years experience
  1. 1

    Design a secure input‑validation layer for a microservice that receives arbitrary JSON and must guard against prototype pollution across multiple downstream services. What components would you include?

  2. 2

    At scale, you have dozens of npm packages, some of which may be vulnerable to prototype pollution. How would you set up a CI/CD pipeline to detect and mitigate these risks?

8+ years experience
  1. 1

    Our organization is migrating a legacy monolith that heavily relies on lodash's merge into a new platform. How would you plan a phased migration to eliminate prototype pollution while keeping feature parity?

  2. 2

    Across multiple teams you notice inconsistent handling of object merging leading to security gaps. Propose an architecture‑level policy and tooling strategy to enforce safe merging practices organization‑wide.

Follow-up Questions

  • Why is Object.prototype a common target for pollution attacks?
  • What trade‑offs exist between deep cloning inputs and performance?
  • How would you handle a third‑party library that performs unsafe merges?