Skip to content

Conversation

@grypez
Copy link
Contributor

@grypez grypez commented Aug 15, 2024

Closes #9

Changes the way the @ocap/shims package builds src/endoify to copy the contents of its imports directly into the file.

Adds tests in @ocap/shims/test that suggest the intended behavior of our bundled shims.

  • the tests are copied from endojs/endo
  • the tests therefore run under ava instead of vitest
  • the tests are picked up by the repo-level test runner

Adds two new dev dependencies in @ocap/shims

  • streamcat
  • ava

Adds an initial test suite (copied from `@endo/ses`) ensuring that
this bundled shims work as intended after import. The primary
behavior under test is that `import '@ocap/shims/endoify'` produces
the same environment as `import 'ses'`. Future tests may also
ensure that the bundled `eventual-send` also  works as intended.
@grypez grypez requested a review from a team as a code owner August 15, 2024 18:03
@grypez grypez force-pushed the refactor-shims-inline-endoify branch from 5fc51f1 to b989843 Compare August 15, 2024 18:05
@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/ava@6.1.3 Transitive: environment, eval, filesystem, network, shell, unsafe +108 3.21 MB novemberborn
npm/promisebuffer@1.0.0 None 0 5.72 kB samgiles
npm/streamcat@2.6.5 None 0 20.8 kB the-ft

View full report↗︎

@socket-security
Copy link

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Deprecated npm/rimraf@3.0.2
  • Reason: Rimraf versions prior to v4 are no longer supported
⚠︎
Deprecated npm/glob@7.2.3
  • Reason: Glob versions prior to v9 are no longer supported
⚠︎
Deprecated npm/inflight@1.0.6
  • Reason: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
⚠︎
Network access npm/node-fetch@2.7.0 🚫
Network access npm/node-fetch@2.7.0 🚫
Network access npm/node-fetch@2.7.0 🚫
Deprecated npm/are-we-there-yet@2.0.0
  • Reason: This package is no longer supported.
⚠︎
Deprecated npm/gauge@3.0.2
  • Reason: This package is no longer supported.
⚠︎
Deprecated npm/npmlog@5.0.1
  • Reason: This package is no longer supported.
⚠︎
New author npm/async-sema@3.1.1 🚫
New author npm/memoize@10.0.0 🚫
New author npm/package-config@5.0.0 🚫
Shell access npm/detect-libc@2.0.3 🚫

View full report↗︎

Next steps

What is a deprecated package?

The maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.

Research the state of the package and determine if there are non-deprecated versions that can be used, or if it should be replaced with a new, supported solution.

What is network access?

This module accesses the network.

Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

What is new author?

A new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.

Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

What is shell access?

This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.

Packages should avoid accessing the shell which can reduce portability, and make it easier for malicious shell access to be introduced.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/rimraf@3.0.2
  • @SocketSecurity ignore npm/glob@7.2.3
  • @SocketSecurity ignore npm/inflight@1.0.6
  • @SocketSecurity ignore npm/node-fetch@2.7.0
  • @SocketSecurity ignore npm/are-we-there-yet@2.0.0
  • @SocketSecurity ignore npm/gauge@3.0.2
  • @SocketSecurity ignore npm/npmlog@5.0.1
  • @SocketSecurity ignore npm/async-sema@3.1.1
  • @SocketSecurity ignore npm/memoize@10.0.0
  • @SocketSecurity ignore npm/package-config@5.0.0
  • @SocketSecurity ignore npm/detect-libc@2.0.3

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of bundle.js looks great. Regarding that I only have one nit, namely that it would be great to avoid the extra dependency (which is unmaintained, not that that's really a concern). I'm wondering whether we can serially pipe the read streams to the same or multiple write streams, skipping the intermediary buffer? Potentially worth a try.

My biggest feedback regards the tests. We should definitely test the shims. However, entraining ava and copying over ses tests is too high of a price. The point of all this is to avoid transforming the ses shim, and thereby preclude any issues with its fidelity. All we need to do for now is convince ourselves that the different components of our shims have been applied successfully. Even something like this would do:

assert(Object.isFrozen(Array.prototype)); // Due to `lockdown()`, and therefore `ses`
assert(typeof HandledPromise !== 'undefined'); // Due to eventual send

vitest should work as the runner for this, and if not, we can consider our options.

await copyFile(path.resolve(src, fileName), path.resolve(dist, fileName));
}
await mkdirp(pkgDist);
await rimraf(`${pkgDist}/*`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my sin originally, but this should be:

Suggested change
await rimraf(`${pkgDist}/*`);
await rimraf(`${pkgDist}/*`, { glob: true });

Without the glob setting, this call will do nothing.

Copy link
Contributor Author

@grypez grypez Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With regards to the streamcat dependency, I can get rid of it and have an implementation that works without it.

With regards to testing, see #9 (comment)

Resolution to the testing issue is a broader problem; in the interest of timely resolution, and considering that the logic of the implementation is quite small and easily human-evaluated, I am considering simply not testing the implementation. My two reservations are that on principle I prefer tested code to untested code, and in particular since everything we do in this repo will depend on the correct behavior of the shim I think contributors would prefer to know as quickly as possible during development that the shim is broken. I can alleviate these reservations slightly by believing that 'almost all of the tests are suddenly failing' would point us to 'perhaps the shim is broken'.

However, given that ava is capable of testing the shim without these issues, my proposed compromise would be that we keep the ava dev dependency and I adapt the minimal test you proposed:

assert(Object.isFrozen(Array.prototype)); // Due to `lockdown()`, and therefore `ses`
assert(typeof HandledPromise !== 'undefined'); // Due to eventual send

As @SMotaal is already doing a deep dive into vitest's AST parser (and whatever conflicts lie beyond), it seems likely we will be able to remove the ava dependency in the future.

@grypez grypez closed this Aug 21, 2024
@grypez grypez deleted the refactor-shims-inline-endoify branch October 4, 2024 16:55
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

Successfully merging this pull request may close these issues.

shims: Bundle external dependencies into endoify.mjs

3 participants