Skip to content

security consideration for shared dependencies #29062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hosseinalipour opened this issue Apr 26, 2025 · 0 comments
Open

security consideration for shared dependencies #29062

hosseinalipour opened this issue Apr 26, 2025 · 0 comments

Comments

@hosseinalipour
Copy link

I'd like to discuss a potential security consideration regarding shared dependencies during module loading.

Consider the standard ESM behavior where different modules importing the same URL receive the same instance (e.g., App imports B, A imports C, C imports B – all get the same B instance).

The potential risk scenario is:

  1. Dependency C loads as part of the module graph resolution.
  2. During its own initialization (top-level code execution), C modifies the shared instance of B.
  3. Later, when the App's code runs, it receives this already-altered version of B, potentially before the App has had a chance to apply its own safeguards like Object.freeze(B).

This "load-time alteration" could lead to unexpected behavior or security vulnerabilities if C acts maliciously or incorrectly.

While Deno's permission system is crucial for limiting the impact of compromised code, and freezing modules after import helps, neither seems to directly prevent this initial modification of a shared module instance during the graph loading phase itself by an earlier-loading dependency.

Is this scenario something the Deno team has considered? What is the recommended approach or Deno's perspective on mitigating this specific risk inherent in shared mutable module instances during load time? Have there been considerations regarding mechanisms, perhaps leveraging loader hooks or specific APIs, that could allow applications to intercept the module instantiation or resolution process? Such a capability could enable preemptive application of security policies (like immediate freezing or wrapping modules in hardened proxies) before a shared instance is provided to potentially untrusted dependencies during graph loading. While ESM's static nature differs significantly from CommonJS, the underlying need for finer control during loading echoes discussions seen in other environments like Node.js (though mechanisms like the now-deprecated require.extensions are not directly comparable given ESM architecture).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant