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 lockdown v0.18.8 (iOS JSC) #6586

Merged
merged 83 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
7ac4040
Format package.json
leotm Jun 7, 2023
8c1b278
Add ses 0.18.4 via Yarn
leotm Jun 7, 2023
4c205b4
Add ses 0.18.4 lockdown shim
leotm Jun 7, 2023
191b45e
Update Babel config to ignore ses.cjs
leotm Jun 7, 2023
4469470
Import ses npm module at entry file
leotm Jun 7, 2023
0f2f915
Call ses lockdown at entry file
leotm Jun 7, 2023
4f9a849
Patch @babel/runtime
leotm Jun 7, 2023
00dd1ac
Patch ethjs/ethjs-contract
leotm Jun 7, 2023
991c926
Fix ethjs/ethjs-contract patch (patch-package fail on fresh install)
leotm Jun 7, 2023
3aba797
Patch ethjs/ethjs-query
leotm Jun 7, 2023
e1e99eb
Fix ethjs/ethjs-query patch (patch-package fail on fresh install)
leotm Jun 7, 2023
a4229b0
Patch react-native
leotm Jun 7, 2023
873716b
Document EngineService init errors w ses lockdown w/o ethjs patches
leotm Jun 7, 2023
745d89a
Document ses lockdown shim import TypeError
leotm Jun 7, 2023
0c542c9
Merge branch 'main' into feature/ses-lockdown-2
leotm Jun 9, 2023
b635b1c
Merge branch 'main' into feature/ses-lockdown-2
leotm Jun 13, 2023
15a8ab7
Merge branch 'main' into feature/ses-lockdown-2
leotm Jun 15, 2023
22bde3a
ESLint ignore lockdown shim
leotm Jun 15, 2023
8186199
Merge branch 'main' into feature/ses-lockdown-2
leotm Jun 22, 2023
401b41f
Merge remote-tracking branch 'upstream/main' into feature/ses-lockdown-2
leotm Jun 27, 2023
d2d2bf4
Update Podfile.lock
leotm Jun 27, 2023
e52f13a
Patch react-native
leotm Jun 28, 2023
28b9db4
Merge branch 'main' into feature/ses-lockdown-2
leotm Jul 17, 2023
243d895
Delete stale @babel/runtime patch
leotm Jul 17, 2023
76cc6e7
Re-patch @babel/runtime
leotm Jul 17, 2023
9d85f38
Revert "Re-patch @babel/runtime"
leotm Jul 25, 2023
3436f11
Merge branch 'main' into feature/ses-lockdown-2
leotm Jul 26, 2023
25c832b
Update CocoaPods lockfile
leotm Jul 31, 2023
d3ce192
Call lockdown first
leotm Jul 31, 2023
237e804
Extract to ses lockdown then shims to preBundle file
leotm Jul 31, 2023
165b444
Merge branch 'main' into feature/ses-lockdown-2
leotm Jul 31, 2023
2f78412
Remove additional shims import
leotm Aug 1, 2023
f5de5eb
Merge branch 'main' into feature/ses-lockdown-2
leotm Aug 2, 2023
e1fbcc0
Merge branch 'main' into feature/ses-lockdown-2
leotm Aug 16, 2023
ed4f49e
Bump SES from 0.18.4 to 0.18.7
leotm Aug 17, 2023
ed36668
Fix lint on SES comment
leotm Aug 17, 2023
e0d5b1b
Bump SES lockdown shim from 0.18.4 to 0.18.7
leotm Aug 17, 2023
b239c69
Disable @babel/plugin-transform-runtime helpers
leotm Aug 28, 2023
0286dfc
Disable RN Promise.prototype.done non-standard polyfill
leotm Aug 28, 2023
5d473a2
Add SES (cjs) with vetted shims pre-v0.18.8 tag plublish
leotm Aug 28, 2023
049a6f8
Use SES 0.18.7 with vetted shims (cjs) pre-v0.18.8 tag plublish
leotm Aug 28, 2023
337d3b8
Replace lockdown with repairIntrinsics, vetted shim (reflect-metadata…
leotm Aug 28, 2023
24d1d30
Update comment on [email protected] lockdown shim issue
leotm Aug 29, 2023
8aeb392
Merge branch 'main' into feature/ses-lockdown-2
leotm Aug 30, 2023
c5b5c23
Add doc comment on SES and Babel getPrototype error
leotm Aug 30, 2023
5b89e9b
Move preBundle.js back into entry file
leotm Aug 30, 2023
310defe
Bake [email protected] into React Native core
leotm Sep 4, 2023
6e252a3
Finalise SES vetted shims clean solution baked into React Native core
leotm Sep 6, 2023
ef28c0c
Merge branch 'main' into feature/ses-lockdown-2
leotm Sep 11, 2023
cd9644a
Remove old/current [email protected] (npm)
leotm Sep 11, 2023
4dd8e84
Remove old SES lockdown.umd.js shim
leotm Sep 11, 2023
300e1ff
Remove stale SES lockdown.umd.js shim from eslintignore
leotm Sep 11, 2023
a773cd4
Fix CI lint (JSDoc indentation)
leotm Sep 11, 2023
ab56846
Merge branch 'main' into feature/ses-lockdown-2
leotm Sep 14, 2023
8904439
Switch off Hermes on Android
leotm Sep 15, 2023
d8a4fa5
Add jsc-android
leotm Sep 15, 2023
9363d32
Revert "Add jsc-android"
leotm Sep 15, 2023
599ab6f
Bump jsc-android 250231.0.0 (default) to 294992.0.0 for BigInt
leotm Sep 15, 2023
8d27f78
Switch org.webkit:android-jsc to android-jsc-intl for BigInt
leotm Sep 15, 2023
7b28ac5
Ignore used jsc-android in depcheckrc
leotm Sep 21, 2023
6cf1e7b
Merge branch 'main' into feature/ses-lockdown-2
leotm Sep 21, 2023
662ec47
Merge branch 'main' into feature/ses-lockdown-2
leotm Sep 24, 2023
f74543a
Merge branch 'main' into feature/ses-lockdown-2
leotm Sep 27, 2023
d8cc393
Update lockdown shim to 0.18.8
leotm Sep 27, 2023
aa44819
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 3, 2023
0913a90
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 9, 2023
930198c
Merge branch 'main' into feature/ses-lockdown-2
legobeat Oct 12, 2023
cc3d365
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 16, 2023
c436a60
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 25, 2023
95c09fb
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 27, 2023
812653e
Merge branch 'main' into feature/ses-lockdown-2
leotm Oct 31, 2023
b20341c
Revert "Switch org.webkit:android-jsc to android-jsc-intl for BigInt"
leotm Nov 2, 2023
7d5a7aa
Revert "Bump jsc-android 250231.0.0 (default) to 294992.0.0 for BigInt"
leotm Nov 2, 2023
6461aa2
Revert "Switch off Hermes on Android"
leotm Nov 2, 2023
792c6f8
Revert "Ignore used jsc-android in depcheckrc"
leotm Nov 2, 2023
4904529
Update RN patch InitCore SES version comment
leotm Nov 2, 2023
ab35ea4
Add RN patch InitCore DevTools comment
leotm Nov 2, 2023
ace8c88
Add RN patch InitCore setUpDOM comment
leotm Nov 2, 2023
25ac5af
Update RN patch InitCore to only call lockdown on iOS
leotm Nov 2, 2023
35fb6d5
Update RN patch InitCore to only call lockdown on iOS and not Hermes
leotm Nov 2, 2023
9b4f859
Merge branch 'main' into feature/ses-lockdown-2
leotm Nov 2, 2023
d88e399
Merge branch 'main' into feature/ses-lockdown-2
leotm Nov 10, 2023
e8eaf91
Merge branch 'main' into feature/ses-lockdown-2
leotm Nov 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ const createStoreAndPersistor = async () => {
* Initialize services after persist is completed
*/
const onPersistComplete = () => {
/**
* EngineService.initalizeEngine(store) with SES/lockdown:
* Requires ethjs nested patches (lib->src)
* - ethjs/ethjs-query
* - ethjs/ethjs-contract
* Otherwise causing the following errors:
* - TypeError: Cannot assign to read only property 'constructor' of object '[object Object]'
* - Error: Requiring module "node_modules/ethjs/node_modules/ethjs-query/lib/index.js", which threw an exception: TypeError:
* - V8: Cannot assign to read only property 'constructor' of object '[object Object]'
* - JSC: Attempted to assign to readonly property
* - node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js
* - V8: TypeError: _$$_REQUIRE(...) is not a constructor
* - TypeError: undefined is not an object (evaluating 'TokenListController.tokenList')
* - V8: SES_UNHANDLED_REJECTION
*/
leotm marked this conversation as resolved.
Show resolved Hide resolved
EngineService.initalizeEngine(store);
Authentication.init(store);
LockManagerService.init(store);
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
ignore: [/ses\.cjs/],
leotm marked this conversation as resolved.
Show resolved Hide resolved
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'transform-inline-environment-variables',
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Importing SES (0.18.7+) here then calling lockdown causes:
// https://github.com/LavaMoat/docs/issues/24

// Importing the SES (0.18.7) lockdown shim here then calling lockdown causes:
// https://github.com/LavaMoat/docs/issues/27
leotm marked this conversation as resolved.
Show resolved Hide resolved

import './shim.js';

// Needed to polyfill random number generation.
import 'react-native-get-random-values';
import '@walletconnect/react-native-compat';
import './shim.js';

import 'react-native-gesture-handler';
import 'react-native-url-polyfill/auto';
Expand Down
13 changes: 13 additions & 0 deletions patches/ethjs++ethjs-contract+0.2.2.patch
leotm marked this conversation as resolved.
Show resolved Hide resolved
leotm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/ethjs/node_modules/ethjs-contract/package.json b/node_modules/ethjs/node_modules/ethjs-contract/package.json
index 8e58ff5..470d00b 100644
--- a/node_modules/ethjs/node_modules/ethjs-contract/package.json
+++ b/node_modules/ethjs/node_modules/ethjs-contract/package.json
@@ -197,7 +197,7 @@
"lint-staged": {
"lint:eslint": "*.js"
},
- "main": "lib/index.js",
+ "main": "src/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.

Just curious, I don't understand here why we needed to point to the src

Copy link
Member Author

@leotm leotm Nov 8, 2023

Choose a reason for hiding this comment

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

good question ^ these couple ethjs contract/query libs we use (transitively via ethjs) to init our engine service
both optimise their bundles with few Babel runtime helpers (notably regenerator and asyncToGenerator)
both currently incompatible with SES, so using their source code instead is less problematic

Copy link
Member Author

@leotm leotm Nov 8, 2023

Choose a reason for hiding this comment

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

so captured the details mentioned here
both in a code comment and issue

Copy link
Member

Choose a reason for hiding this comment

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

Have you considered patching babel-runtime and regenerator-runtime instead? They're used in quite a few packages (including some that we'll be introducing soon to the codebase, like our ethjs-* forks of packages like this one). It may be easier to fix the problem at the source. The extension already has patches for them to make them SES compatible.

"name": "ethjs-contract",
"pre-commit": "build",
"repository": {
13 changes: 13 additions & 0 deletions patches/ethjs++ethjs-query+0.3.7.patch
leotm marked this conversation as resolved.
Show resolved Hide resolved
leotm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/ethjs/node_modules/ethjs-query/package.json b/node_modules/ethjs/node_modules/ethjs-query/package.json
index fb82d51..503159c 100644
--- a/node_modules/ethjs/node_modules/ethjs-query/package.json
+++ b/node_modules/ethjs/node_modules/ethjs-query/package.json
@@ -2,7 +2,7 @@
"name": "ethjs-query",
"version": "0.3.7",
"description": "A simple query layer for the Ethereum RPC.",
- "main": "lib/index.js",
+ "main": "src/index.js",
"files": [
"dist",
"internals",
58 changes: 58 additions & 0 deletions patches/react-native+0.71.14.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
diff --git a/node_modules/react-native/Libraries/Core/InitializeCore.js b/node_modules/react-native/Libraries/Core/InitializeCore.js
index 1379ffd..340f48d 100644
--- a/node_modules/react-native/Libraries/Core/InitializeCore.js
+++ b/node_modules/react-native/Libraries/Core/InitializeCore.js
@@ -24,26 +24,51 @@

'use strict';

+const Platform = require('../Utilities/Platform');
+
+if (Platform.OS === 'ios' && !global?.HermesInternal) {
leotm marked this conversation as resolved.
Show resolved Hide resolved
+ require('../../../../ses.cjs'); // [email protected]
leotm marked this conversation as resolved.
Show resolved Hide resolved
leotm marked this conversation as resolved.
Show resolved Hide resolved
+ /**
+ * Without consoleTaming: 'unsafe' causes:
+ * - Attempting to define property on object that is not extensible.
+ * Without errorTrapping 'none' causes:
+ * - TypeError: undefined is not a function (near '...globalThis.process.on...')
+ * Without unhandledRejectionTrapping 'none' causes:
+ * - TypeError: globalThis.process.on is not a function. (In 'globalThis.process.on('unhandledRejection', h.unhandledRejectionHandler)', 'globalThis.process.on' is undefined)
+ * overrideTaming 'severe' is ideal (default override?)
+ * Nb: global.process is only partially shimmed, which confuses SES
+ * Nb: All are Unhandled JS Exceptions, since we call lockdown before setUpErrorHandling
+ */
+ repairIntrinsics({ consoleTaming: 'unsafe', errorTrapping: 'none', unhandledRejectionTrapping: 'none', overrideTaming: 'severe' });
leotm marked this conversation as resolved.
Show resolved Hide resolved
leotm marked this conversation as resolved.
Show resolved Hide resolved
+ require('reflect-metadata'); // Vetted shim required to fix: https://github.com/LavaMoat/docs/issues/26
+ hardenIntrinsics();
+}
+
const start = Date.now();

require('./setUpGlobals');
+// require('./setUpDOM'); Introduced in RN v0.72, ensure included when upgrading patch
leotm marked this conversation as resolved.
Show resolved Hide resolved
require('./setUpPerformance');
require('./setUpErrorHandling');
+
require('./polyfillPromise');
+
require('./setUpRegeneratorRuntime');
+
require('./setUpTimers');
require('./setUpXHR');
+
require('./setUpAlert');
require('./setUpNavigator');
require('./setUpBatchedBridge');
require('./setUpSegmentFetcher');
if (__DEV__) {
require('./checkNativeVersion');
- require('./setUpDeveloperTools');
+ require('./setUpDeveloperTools'); // console.log calls visible in Metro from here
require('../LogBox/LogBox').install();
}

-require('../ReactNative/AppRegistry');
+require('../ReactNative/AppRegistry'); // reflect-metadata imported after here causes: https://github.com/LavaMoat/docs/issues/26

const GlobalPerformanceLogger = require('../Utilities/GlobalPerformanceLogger');
// We could just call GlobalPerformanceLogger.markPoint at the top of the file,
diff --git a/node_modules/react-native/ReactAndroid/build.gradle b/node_modules/react-native/ReactAndroid/build.gradle
index 155cb59..053550c 100644
--- a/node_modules/react-native/ReactAndroid/build.gradle
Expand Down
Loading
Loading