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

Proof of Concept Insights - lockdown() options #3

Closed
bentobox19 opened this issue Feb 25, 2022 · 2 comments
Closed

Proof of Concept Insights - lockdown() options #3

bentobox19 opened this issue Feb 25, 2022 · 2 comments

Comments

@bentobox19
Copy link
Contributor

PoC

https://github.com/LavaMoat/docs/blob/main/react-native-and-ses-lockdown.md

Discussion

The SES function lockdown()is called with the following option:

lockdown({consoleTaming: 'unsafe'});

This option was added after the following report:

This line is (silently, without logs, nor anything) breaking my mobile app:
globalThis.console = /** @type {Console} */consoleRecord.console;

From Agoric the following advice

You might try the lockdown option consoleTaming: "unsafe"
It will be interesting if that gets you past the issue, though it is unsafe as described on the tin.
The purpose of the line is to replace the initial realm’s console with one that can reveal stack traces for any error that gets logged to it.

@leotm leotm added jsc JavaScriptCore lockdown and removed jsc JavaScriptCore labels Mar 12, 2023
@leotm leotm added this to the MM + Lockdown milestone Mar 20, 2023
@leotm
Copy link
Member

leotm commented Mar 20, 2023

Can confirm we need this option ^ for general React Native debugging with stacktraces
then for error monitoring deps (e.g. Sentry/BugSnag/etc) to capture error stacktraces w sourcemaps to monitor/debug prod

Following up latest RN PoCs

If we add custom error class

class CustomError extends Error {
  constructor(foo = 'bar', ...params) {
    // Pass remaining arguments (including vendor specific ones) to parent constructor
    super(...params);

    // Maintains proper stack trace for where our error was thrown (only available on V8)
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, CustomError);
    }

    this.name = 'CustomError';
    // Custom debugging information
    this.foo = foo;
    this.date = new Date();
  }
}

and create custom Button to trigger it

          <Button
            title="Click to console.error class CustomError"
            onPress={() => {
              try {
                throw new CustomError('baz', 'bazMessage');
              } catch (e) {
                console.error(e.name); // CustomError
                console.error(e.foo); // baz
                console.error(e.message); // bazMessage
                console.error(e.stack); // stacktrace
              }
            }}
          />

Giving below vanilla RN example

example

lockdown(); Default 'safe' settings

https://github.com/endojs/endo/blob/master/packages/ses/docs/reference.md#options-quick-reference
Screenshot 2023-03-20 at 18 56 30

consoleTaming Options
https://github.com/endojs/endo/blob/master/packages/ses/docs/reference.md#consoletaming-options

safe

Our stacktace is now kaputt ❗ (above) as expected and all we see is CustomError without sanitised props logged
followed by additional TypeError from SES attempting to lockdown the console

Whereas lockdown({consoleTaming: 'unsafe'});

unsafe

We now have our full stacktrace back 🎉 traced to Button.props.onPress and CustomError props logged locally
and once again for error monitoring deps (e.g. Sentry/BugSnag/etc) to capture them with sourcemaps to debug production

@leotm leotm closed this as completed Mar 20, 2023
@leotm
Copy link
Member

leotm commented Mar 20, 2023

nb: While we're here, may be worth exploring our full suite of opts

// node_modules/ses/types.d.ts
export interface LockdownOptions {
  regExpTaming?: 'safe' | 'unsafe';
  localeTaming?: 'safe' | 'unsafe';
  consoleTaming?: 'safe' | 'unsafe';
  errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
  unhandledRejectionTrapping?: 'report' | 'none';
  errorTaming?: 'safe' | 'unsafe';
  dateTaming?: 'safe' | 'unsafe'; // deprecated
  mathTaming?: 'safe' | 'unsafe'; // deprecated
  evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
  stackFiltering?: 'concise' | 'verbose';
  overrideTaming?: 'moderate' | 'min' | 'severe';
  overrideDebug?: Array<string>;
  domainTaming?: 'safe' | 'unsafe';
}

few mentioned once again in
https://github.com/endojs/endo/blob/master/packages/ses/docs/reference.md#options-quick-reference

TBD from remaining metamask-mobile integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants