Skip to content

Support re exp for scuttling avoid props#405

Merged
weizman merged 10 commits into
mainfrom
weizman-support-re-for-scuttling-avoid-props
Nov 16, 2022
Merged

Support re exp for scuttling avoid props#405
weizman merged 10 commits into
mainfrom
weizman-support-re-for-scuttling-avoid-props

Conversation

@weizman

@weizman weizman commented Nov 16, 2022

Copy link
Copy Markdown
Member
  • This PR comes to allow passing regular expressions values in the scuttleGlobalThisExceptions optional argument in addition to the already existing string values support.

Before:

scuttleGlobalThisExceptions = ['alert', 'HTMLSpanElement', 'HTMLDivElement', 'HTMLAnchorElement']

After:

scuttleGlobalThisExceptions = ['alert', /HTML[a-zA-Z]*Element/]

@weizman

weizman commented Nov 16, 2022

Copy link
Copy Markdown
Member Author

Why are we supporting this?

While trying to integrate the new scuttling feature into MetaMask web app we learned that in its test env where a chrome driver is used, the internals of the driver sets in different occasions random props to the global object as part of its legitimate flow. The scuttling feature takes these props and scuttled them which interferes with the normal flow of the driver.

We would like to except those properties but they are random with a recurring pattern cdc_<RANDOM>_{Promise/Array/Function}.

Being able to scuttle props by a regex and not a hardcoded string gives us the ability to treat that

@kumavis kumavis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please document that strings starting with a forward slash are interpreted as regexp

for implementation comparison: https://github.com/IonicaBizau/regex-parser.js/blob/master/lib/index.js#L11-L28

@weizman: fix ba2d4c8

Comment thread packages/browserify/test/util.js
Comment thread packages/core/src/generateKernel.js
Comment thread packages/core/src/kernelCoreTemplate.js
Comment thread packages/core/test/scenarios/scuttle.js Outdated
Comment thread packages/lavapack/src/pack.js
Comment thread packages/core/src/kernelCoreTemplate.js Outdated
Comment thread packages/core/test/scenarios/scuttle.js
Comment thread packages/lavapack/src/runtime.js
Co-authored-by: kumavis <kumavis@users.noreply.github.com>
@weizman weizman requested a review from kumavis November 16, 2022 19:12
props.push(...Object.getOwnPropertyNames(proto)))

for (let i = 0; i < extraPropsToAvoid.length; i++) {
const prop = extraPropsToAvoid[i]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to make sure: it seems we can trust the input here as coming from the trusted initialization code, right?

if (avoid instanceof RegExp && avoid.test(prop)) {
return true
}
if (propsToAvoid.has(prop)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(could) create a test covering that it's not possible to accidentally match the string representation of the regex by setting window['/as.good.a.field.name.as.any/']

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not too worried about such a scenario

if (scuttleGlobalThisExceptions) {
// toString regexps if there's any
for (let i = 0; i < scuttleGlobalThisExceptions.length; i++) {
scuttleGlobalThisExceptions[i] = String(scuttleGlobalThisExceptions[i])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I forgot why, but someone told me

a = `${thingToTurnToString}` 

is better. I never verified and don't remember the reasoning though. 🙈

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Guess we'll never know 😱😱😱😱

@naugtur naugtur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/lavapack/src/runtime.js Outdated
continue
}
const parts = prop.split('/');
extraPropsToAvoid[i] = new RegExp(parts.slice(1, -1).join('/'), parts[parts.length - 1])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

regenerate runtime

@kumavis

kumavis commented Nov 16, 2022

Copy link
Copy Markdown
Member

looks good, plz regenerate lavapack runtime

@weizman weizman merged commit 7348a53 into main Nov 16, 2022
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