Skip to content
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

feat(ses): call lockdown before bundling SES shim #2337

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

leotm
Copy link
Contributor

@leotm leotm commented Jun 28, 2024

Description

Call lockdown before bundling the SES shim

Discussion: https://youtu.be/qGGeACz4cyM

Security Considerations

Does this change introduce new assumptions or dependencies that, if violated, could introduce security vulnerabilities? How does this PR change the boundaries between mutually-suspicious components? What new authorities are introduced by this change, perhaps by new API calls?

  • bundle now fails (TypeError) to build if non-standard JS called after lockdown()
  • yarn build now also logs to console (e.g. Removing unpermitted intrinsics) if non-standard JS called before lockdown()

Scaling Considerations

Does this change require or encourage significant increase in consumption of CPU cycles, RAM, on-chain storage, message exchanges, or other scarce resources? If so, can that be prevented or mitigated?

Documentation Considerations

Give our docs folks some hints about what needs to be described to downstream users. Backwards compatibility: what happens to existing data or deployments when this code is shipped? Do we need to instruct users to do something to upgrade their saved data? If there is no upgrade path possible, how bad will that be for users?

Testing Considerations

Every PR should of course come with tests of its own functionality. What additional tests are still needed beyond those unit tests? How does this affect CI, other test automation, or the testnet?

Compatibility Considerations

Does this change break any prior usage patterns? Does this change allow usage patterns to evolve?

Upgrade Considerations

What aspects of this PR are relevant to upgrading live production systems, and how should they be addressed?

Include *BREAKING*: in the commit message with migration instructions for any breaking change.

Update NEWS.md for user-facing changes.

Delete guidance from pull request description before merge (including this!)

@leotm leotm marked this pull request as ready for review June 28, 2024 14:27
Comment on lines 3 to 2
lockdown();

import '../index.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this does not actually change the order in which things happen, at least in the absence of cyclic imports. All imported modules are evaluated/initialized before the code in this module starts evaluation/initialization. So either way, ../index.js initialization will happen before this call to lockdown.

Attn @kriskowal

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 true. To interleave behavior relative to other imports, we have to use a module like lockdown.js that just calls lockdown(). So,

import '../index.js'; // or maybe import 'ses' reflexively works now
import './lockdown.js'; // just lockdown()

This insures that ./index.js initializes before you call lockdown().

It’s unclear why the tests pass with this defect. It might be that we need to test yarn build under yarn test.

Copy link
Contributor Author

@leotm leotm Jul 1, 2024

Choose a reason for hiding this comment

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

makes sense ^ reverted feat(ses): call lockdown earlier, looks good now

import './lockdown.js'; // just lockdown()

think we meant import '../lockdown.js'; right
if we prefer this vs import '../index.js';
seems either is fine, since they're both importing the same index file

ah so we should import both, done here 82a4bb4

then hopefully add/update a test to ensure ../lockdown.js is imported before calling lockdown()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s unclear why the tests pass with this defect. It might be that we need to test yarn build under yarn test.

yeah the tests still pass calling lockdown() too early before the imports 🤔

"test": "tsd && ava",

even when doing a clean build before "test": "yarn prepare && tsd && ava", if that's what we meant

@leotm leotm requested review from erights and kriskowal July 1, 2024 16:27
/* global process */

import '../index.js';
Copy link
Contributor Author

@leotm leotm Jul 1, 2024

Choose a reason for hiding this comment

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

Suggested change
import '../index.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import 'ses';

also seems ok here (as mentioned earlier)

Copy link
Contributor

@erights erights left a comment

Choose a reason for hiding this comment

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

I'm approving to clear my previous "request changes". FWIW LGTM, but on this I defer to @kriskowal . Please wait for an approval from him.

Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

Posted the required change. Thank you for engaging!

packages/ses/scripts/bundle.js Outdated Show resolved Hide resolved
leotm added a commit to leotm/endo that referenced this pull request Jul 5, 2024
resolve: endojs#2337 (comment)

Co-authored-by: Kris Kowal <kriskowal@kriskowal.com>
@leotm leotm requested a review from kriskowal July 5, 2024 14:46
leotm added a commit to leotm/endo that referenced this pull request Jul 8, 2024
resolve: endojs#2337 (comment)

Co-authored-by: Kris Kowal <kriskowal@kriskowal.com>
@leotm leotm force-pushed the lockdown-before-bundling-ses branch from 23cd2cb to fb2c591 Compare July 8, 2024 17:19
@kriskowal kriskowal force-pushed the lockdown-before-bundling-ses branch from fb2c591 to 4f528a5 Compare August 1, 2024 20:24
@kriskowal kriskowal enabled auto-merge (squash) August 1, 2024 20:24
@kriskowal kriskowal merged commit 8c01dd4 into endojs:master Aug 1, 2024
17 checks passed
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.

3 participants