-
Notifications
You must be signed in to change notification settings - Fork 564
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
Harden endowments #1058
Harden endowments #1058
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #1058 +/- ##
==========================================
- Coverage 95.26% 94.04% -1.23%
==========================================
Files 134 137 +3
Lines 4289 5644 +1355
Branches 729 836 +107
==========================================
+ Hits 4086 5308 +1222
- Misses 203 336 +133
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
5906e3d
to
9896bd8
Compare
9896bd8
to
3c1ed7a
Compare
7cbccb0
to
da48985
Compare
packages/snaps-execution-environments/src/common/endowments/hardenedEndowments.ava.test.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/abortController.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/endowmentModules.ava.test.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/interval.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts
Show resolved
Hide resolved
ca8bef4
to
91df7c1
Compare
packages/snaps-execution-environments/src/common/endowments/security-utils/object-walker.ts
Outdated
Show resolved
Hide resolved
7b80595
to
170940e
Compare
packages/snaps-execution-environments/src/common/endowments/abortController.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/abortController.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/commonEndowmentFactory.ts
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/commonEndowmentFactory.ava.test.ts
Outdated
Show resolved
Hide resolved
when you rebase main you'll need to harden the new Date endowment too. |
a24dd82
to
c9a2ddb
Compare
packages/snaps-execution-environments/src/common/endowments/commonEndowmentFactory.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/endowmentModules.ava.test.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/endowmentModules.ava.test.ts.md
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/hardenedEndowments.ava.test.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/index.ts
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/update-coverage-thresholds.js
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/update-coverage-thresholds.js
Outdated
Show resolved
Hide resolved
packages/snaps-execution-environments/src/common/endowments/hardenedEndowments.ava.test.ts
Outdated
Show resolved
Hide resolved
4841c50
to
7807ebe
Compare
Update AVA config Add harden for default endowments and test Add some refactoring and fix coverage issues Add endowment registry Add hardening for special endowment cases (snap & ethereum) Refactor nyc config Revert hardening of the ethereum endowment Update ava test runner config Revert default-endowments.ts Additionally harden args and returned values Add script for updating coverage thresholds Refactor tests related to hardening of the endowments (optimization) Update coverage thresholds after refactoring Add tests for endowment modules Add object walker utility Integrate object-walker into the AVA security tests and do some refactoring Revert hardening of a snap endowment in index.ts (for now) Manually resolve coverage threshold confusion after deleting line of code Refactor endowment module tests Improve prototype security checks snapshot test proposal Refactor hardening of the interval and timeout endowments Remove specific test for interval and timeout Fix lint and threshold issues after test refactoring and rebasing Add refactoring for common endowment factories Refactor endowments to resolve issue with Text decoder/encoder Add Date to hardened endowments Add console to hardened endowments Revert adding console to the hardening list Fix conflicted config things after rebase Add wrapper for the AbortController Resolve issues after rebase Add custom AbortSignal endowment Revert changes added for AbortController and AbortSignal Fix after rebase Add hardening for new custom Date endowment Add lavamoat object walker integration Add refactoring changes Add another batch of refactoring changes Refactor walker callback function Add fix
935cb3c
to
ddf5fc7
Compare
Fixes: #1018
This PR will ensure that each endowment is passed to the
SES
harden
function before exported.Note: This is not final hardening work. This is one step closer to completing the epic. Half of the work is preparation after researching and identifying a nature of each endowment. Next steps might be continued and followed in the tickets: #1018 and #1017 (if needed).
Attenuated endowments
Each (existing) attenuated endowment located under
/src/common/endowments
folder insidesnaps-execution-environments
repository is modified to handle exported functions or objects throughharden()
. All endowments of this type are tested for their security properties within other endowments in thehardenedEndowments.ava.test.ts
.Common (default javascript) endowments
All endowments* exported as
DEFAULT_ENDOWMENTS
fromsnaps-utils
are now made as custom and all of them are passed to theharden
function before final export.All endowments are consolidated within
buildCommonEndowments
function that will provide factories for all of them, after harden is applied to each.Special endowments
There are two endowments considered as special:
ethereum
andsnap
.It is discovered that hardening of the
ethereum
endowment also known asEIP-1193 Provider
cannot be done in the same place or within thesnaps-execution-environments
package as it is now, becausesnaps-controllers
package is trying to update it in the process which is causing major failures. Further research is required on this, hence it is proposed that this work continue in the next task allocated in the same epic. Also, these endowments are very specific and encapsulated, hence, additional testing approaches might be required.Testing
Each endowment security is tested in
hardenedEndowments.ava.test.ts
. Only AVA test runner is running security related files and testing everything exposed to the functions from SES (harden).There are four major scenarios applied for testing depending on the type of the endowment:
this
through object endowments or instances of the constructor functions.There are three major endowment types identified during the research and testing. These are represented in the table below with test scenarios applied for each.
__proto__
(3)Configuration changes
.c8rc.json
- Removed text report for coverage when running AVA tests (coverage report from AVA will not be reported in console independently anymore as it is redundant, merged coverage will be displayed at the end of the process).nyc.config.js
- New configuration file added. This will enable coverage threshold check after coverage merge process is completed. So this will also enable failure and exit with code 1 when coverage thresholds are not satisfied. It is required because Jest cannot be responsible for the coverage threshold checks as it is only checking its own coverage during its run.ava.config.js
- Removedconcurrency
settings since it's the best option for AVA to handle this automatically and by default it will distribute tests according to the availability of CPU cores. Thetimeout
configurations is added and set to 30 seconds. This is required because AVA needs more time to start running, if the timeout is set too low or default, it can cause timeout failure during the test run on the CI pipeline. This does not means that it will use whole 30 seconds, but just how much is needed (part of it). Ava tests are running fine after the run has started. The only issue was the moment when it's loading tests which can take little bit longer and fail before it started.jest.config.js
- Coverage threshold is removed so the Jest will not be checking it anymore (only merged coverage can be checked at the runtime). Coverage provider is returned to bev8
since AVA is using the same and in order for merge process to work, it is needed to use the same coverage reporter.jest.environments.js
- Because Jest has problem with running SES,harden
function is mocked in the global environment with the function that will just return anything passed to it. This is the only way so far how it can work withharden
involved, etc.package.json
-jest-it-up
is removed from usage, because if Jest configuration file is updated with the thresholds, it will then take the responsibility for threshold checks and fail on its own run (it will not use merged coverage, etc.). Themerge:coverage
command is updated so the merged coverage report will be displayed in the console after it completed testing process. Afterwards, a newly added scriptupdate-coverage-thresholds.js
will run an update of the new coverage thresholds if required.List of endowments and their types
Notes about types of endowments:
function
- All hardened in a simple way by applyingharden
function on them. Special cases such assetTimeout
,setInterval
,fetch
... are already handled in a wrapped way plus now additionally hardened withharden
.constructor
- All of these are hardened and tested.object
- All of them are hardened and tested except theethereum
andsnap
endowment which is still in research process.Additional notes:
Because of complexity and additional requirements
ethereum
andsnap
endowment should be hardened and tested in the other PR.