Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 3.53 KB

File metadata and controls

29 lines (23 loc) · 3.53 KB

Threat Model Analysis for isaacs/inherits

  • Threat: Malicious Package Substitution (Supply Chain Attack)

    • Description: An attacker publishes a malicious package to npm with a name similar to inherits (typosquatting) or compromises the official inherits package itself. The malicious package mimics the inherits API but contains malicious code. The attacker might use social engineering or exploit vulnerabilities in other parts of the developer's workflow to trick them into installing the malicious package. This is a direct threat because the vulnerability lies within the inherits package (or a fraudulent replacement) itself.
    • Impact: Complete application compromise. The attacker's code runs with the privileges of the application, potentially allowing data theft, system modification, or denial of service. The attacker's code could be injected into any object created using the compromised inheritance.
    • Affected Component: The entire inherits module.
    • Risk Severity: Critical
    • Mitigation Strategies:
      • Lockfiles: Use package-lock.json (npm) or yarn.lock (Yarn) to ensure consistent dependency versions.
      • Dependency Auditing: Regularly run npm audit or use tools like Snyk to identify known vulnerabilities in dependencies.
      • Private Registry/Mirroring: Use a private npm registry or mirror to control the source of dependencies and reduce reliance on the public npm registry.
      • Manual Verification: Before installing, carefully check the package name, author, and download counts on npm. Look for red flags like recent publication, low download counts, or suspicious author information.
      • Code Reviews: Include dependency changes in code reviews, scrutinizing any new or updated packages.
  • Threat: Prototype Chain Tampering (Post-Inheritance)
    • Description: Although the tampering occurs after inherits is called, the fact that inherits sets up the prototype chain makes this a directly related threat. Other code (malicious or buggy) modifies the prototype chain that inherits established. This could involve __proto__ manipulation or Object.setPrototypeOf. The attacker aims to inject or overwrite methods on the prototype.
    • Impact: Unpredictable application behavior, potential security vulnerabilities. If an attacker can modify the prototype of a commonly used object (made accessible via inherits), they could inject code that executes in unexpected contexts, leading to privilege escalation or data leakage.
    • Affected Component: The prototype chain established by the inherits.inherits function.
    • Risk Severity: High
    • Mitigation Strategies:
      • Immutability: Use Object.freeze() on constructor prototypes immediately after the inheritance chain is established using inherits. This is the most direct and effective mitigation.
      • Code Reviews: Carefully review code for any attempts to modify prototypes after the initial setup with inherits. Flag any use of __proto__ or Object.setPrototypeOf outside of the inherits call.
      • Defensive Programming: Avoid relying on the immutability of prototypes, even with freezing. Use defensive copying where appropriate.