-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix(ses): work around #2348 linenumber bug #2355
fix(ses): work around #2348 linenumber bug #2355
Conversation
a2d3b66
to
46b22be
Compare
Why not re-use the existing |
I concur. This new case is a kind of As a develop I would expect that |
I think I concur as well. I'll try it out and we'll see what we think. |
Approach looks good. I propose |
Done! PTAL It is indeed a much better approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving modulo copy changes to remove references to Ava and TypeScript.
*BREAKING*: Importing `@endo/lockdown/commit-debug.js` will now endanger integrity as well, in order to get better line numbers. `@endo/lockdown/commit-debug.js` should normally be used only for development/debugging/testing scenarios, where it is not potentially in contact with any genuinely malicious code. For those cases, there is no BREAKING change here. But we're flagging a potentially breaking change in case anyone is importing `@endo/lockdown/commit-debug.js` in scenarios where potentially malicious code is a concern. Such uses should be revised to avoid setting `errorTaming: 'unsafe-debug'`. Closes: #XXXX Refs: #2355 Agoric/agoric-sdk#9711 ## Description In #2355 , we introduced a new `errorTaming` setting, `'unsafe-debug'`, to sacrifice more security for a better debugging experience. In many ways it would have been more convenient to modify `'unsafe'` to do this, rather than introduce a new setting. But we did not because the `'unsafe'` setting was already documented as threatening only confidentiality, not integrity. Many production scenarios don't need the `'safe'` level of confidentiality defense, and so have been using `errorTaming: 'unsafe'` in production, as shown below. Thus, a less-safe form had to be a new mode, so the loss of safety was purely opt-in. However, for uses that were clearly development-only uses, especially those that are explicitly about testing/debugging, they often inherit these lockdown settings from a long chain of imports bottoming out in ```js import '@endo/lockdown/commit-debug.js'; ``` Since this import is explicitly named something-debug, and since none of the production uses of `errorTaming: 'unsafe'` that we are aware of inherit it from `endo/lockdown/commit-debug.js`, it seems we could recover the convenience for those testing/debugging uses by modifying this file in place, with an acceptable security risk. This PR does so. ### Some existing uses of `errorTaming: 'unsafe'` Some of these are in production code https://github.com/LavaMoat/LavaMoat/blob/1cb057b281d46d2564872f53c2769bf4c4cb0ba5/packages/webpack/src/plugin.js#L54 https://github.com/LavaMoat/LavaMoat/blob/1cb057b281d46d2564872f53c2769bf4c4cb0ba5/packages/core/src/kernelTemplate.js#L60 https://github.com/LavaMoat/LavaMoat/blob/1cb057b281d46d2564872f53c2769bf4c4cb0ba5/packages/webpack/src/plugin.js#L54 https://github.com/MetaMask/metamask-extension/blob/7b3450a294a2fe5751726a9c33d6fa0b564f03dd/app/scripts/lockdown-run.js#L6 https://github.com/MetaMask/snaps/blob/0a265dcf9de73a16a7b50cc47681fe6da179383a/packages/snaps-utils/src/eval-worker.ts#L14 https://github.com/MetaMask/snaps/blob/0a265dcf9de73a16a7b50cc47681fe6da179383a/packages/snaps-execution-environments/src/common/lockdown/lockdown.ts#L15 From the [psm.inter.trade](https://psm.inter.trade/) console ![psm inter trade-debug-console](https://github.com/user-attachments/assets/cd01501c-9a0c-43d6-a529-67fd1ca3ae43) ### Security Considerations As explained above. If there are any production uses that get their lockdown settings by importing `@endo/lockdown/commit-debug.js`, they will experience a silent loss of security when they upgrade to depend on this more recent version. We are not aware of any such cases. Because of the explicit "debug" in the name, we expect such cases to be rare. But we have no way to confirm they do not exist. Reviewers, please let me know if you'd like me to change from a `fix:` to a `fix!` because of this silent loss of security on upgrading the dependency. ### Scaling Considerations none ### Documentation Considerations #2355 documents the differences between `'unsafe'` and `'unsafe-debug'` for both security and functionality. - [ ] Somewhere we need to explain that `endo/lockdown/commit-debug.js` has changed in place, explaining the difference. ### Testing Considerations Most of our tests inherit their `lockdown` settings from importing `@endo/lockdown/commit-debug.js`, so these test would experience both the security loss --- which should not matter for testing --- and functionality gain of seeing correct line-numbers into transpiled code, such as TypeScript sources. ### Compatibility Considerations For development purposes, practically none, since the loss of security in question is unlikely to matter. The improvement in line numbers will help developers looking at stack traces, but is unlikely to affect any code. This change is not compatible with production code that imports `@endo/lockdown/commit-debug.js`. But as the name indicates, production code should not have been importing this file anyway. ### Upgrade Considerations No upgrade issues - [ ] Include `*BREAKING*:` in the commit message with migration instructions for any breaking change. - [x] Update `NEWS.md` for user-facing changes.
closes: #8662 refs: endojs/endo#2355 endojs/endo#2348 ## Description endojs/endo#2355 makes it possible to see accurate line numbers into TypeScript Ava tests run under Node, which would fix #8662 as of the next endo-release-agoric-sdk-sync cycle. To get this benefit before then, this PR turns endojs/endo#2355 into an agoric-sdk patch of endo. This PR also adds a test case to demonstrate that the fix works, and updates the `env.md` file to document the new environment variable for enabling this behavior. ### Security Considerations See Security Consideration of endojs/endo#2355 . In short, this feature sacrifices security for a better test-debug experience, which is fine for ***development only***. ### Scaling Considerations none ### Documentation Considerations See Documentation Considerations of endojs/endo#2355 ### Testing Considerations This PR effectively serves as a test both for endojs/endo#2355 and for the corresponding patch in this PR. ### Upgrade Considerations none.
Closes: #2348
Refs: Agoric/agoric-sdk#9711 #1798 #1799 Agoric/agoric-sdk#8662 Agoric/agoric-sdk#9700
Description
Prior to this PR, when you ran on Ava on Node a test written in TypeScript, you'd see something like the following in your stack traces.
This is because the TypeScript compiler compiles a TypeScripy file into one line
of JavaScript with a sourceMap that should map back into original
source positions. Node specifically makes use of that sourceMap
to produce original line-numbers. However, Node does this in a way
that resists virtualization, so the normal SES error taming cannot use
this sourceMap info.
By default, this PR does not change this behavior. However it recognizes a new
SUPPRESS_NODE_ERROR_TAMING
environment variable.With the
SUPPRESS_NODE_ERROR_TAMING
environment variable absentor set to
'disabled'
, you should still see stack traces as shown aboveHowever, if you also set the
SUPPRESS_NODE_ERROR_TAMING
environmentvariable
'enabled'
, for example by doing$ export SUPPRESS_NODE_ERROR_TAMING=enabled
at a bash shell, then when you run this test you should instead see
something like
At Agoric/agoric-sdk#9711 I both
Security Considerations
This new behavior only applies when
errorTaming: 'unsafe'
, on v8, and with this new environment variable enabled.Setting
errorTaming: 'unsafe'
already flags to sacrifice some security for a better debugging experience. But the loss of security is moderate enough --- mostly confidentiality rather than integrity --- that some may chose this setting for some production purposes.The new behavior is a more severe loss of security that really should be used only during development, not production, when even a severe loss of security is usually not an issue.
Scaling Considerations
none
Documentation Considerations
The behavior prior to this PR or without this environment variable enabled is an unpleasant debugging experience. However, developers won't know how to repair it, or even that it can be repaired, without explanation. Even then, the difficultly of discovery in a problem.
The names
SUPPRESS_NODE_ERROR_TAMING
and the settings'enabled'
and'disabled'
are by no means clear expressions of what this does. Reviewers, better names would be appreciated!Testing Considerations
The point. As developers write and run tests written in TypeScript, they need to iterate with problems revealed by the tests, for which they need good line numbers, including into the test code.
When the environment variable is enabled, the new behavior broke some SES tests written specifically to test the old behavior. This would not happen under CI because the environment variable is not set by default, and so may not have been noticed. But it was revealed in local testing. To repair this, this PR also sets those tests up to set
process.env.SUPPRESS_NODE_ERROR_TAMING
to'disabled'
before lockdown, protecting those tests from the external environment variable setting.Awkwardly, at the moment Agoric/agoric-sdk#9711 serves as the only test of this PR. This is because I failed to figure out how to configure things so I can run TypeScript tests under Ava, like Agoric/agoric-sdk#9711 does. I tried cargo culting the configs that seemed relevant, but it didn't work.
Reviewers, if you let me know how to do this, I'll duplicate the test case from Agoric/agoric-sdk#9711 here, which would be good.
Compatibility Considerations
With the environment variable absent or disabled, there should be zero difference in behavior, so none.
In a development environment where this environment variable is enabled, some stack traces will be different. But outside of SES itself, nothing should depend on the contents of stack traces, so again none.
Upgrade Considerations
No upgrade considerations.
Nothing BREAKING.
NEWS.md
for user-facing changes.