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

Limit Dapp permissions to primary account #8653

Merged
merged 5 commits into from
May 28, 2020
Merged

Limit Dapp permissions to primary account #8653

merged 5 commits into from
May 28, 2020

Conversation

brad-decker
Copy link
Contributor

@brad-decker brad-decker commented May 26, 2020

Closes #8651

Uses the new limitResponseLength caveat exposed in rpc-cap to limit the Dapp's permission to only be able to access the primary account. This is step 1 of a two PR(+) contribution to add the ability for Dapp authors to request permission to interact with all connected accounts. This PR is a requirement for v8 RC

@brad-decker brad-decker requested a review from a team as a code owner May 26, 2020 21:05
@brad-decker brad-decker marked this pull request as draft May 26, 2020 21:05
@brad-decker brad-decker requested a review from rekmarks May 26, 2020 21:06
@brad-decker
Copy link
Contributor Author

@rekmarks I tested locally with a locally running test-dapp with some console.log statements to confirm I was getting the expected length of response. ➕ It looks like its working but I'm sure this missing some finesse on how we can test it etc.

@brad-decker brad-decker force-pushed the permissions branch 3 times, most recently from 9f2b709 to c035cdc Compare May 27, 2020 19:09
@brad-decker brad-decker marked this pull request as ready for review May 27, 2020 21:07
@metamaskbot
Copy link
Collaborator

Builds ready [0752434]
Page Load Metrics (689 ± 79 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33166503215
domContentLoaded34898068716479
load34998168916479
domInteractive34797968716479

Comment on lines +433 to +443
ethAccounts.caveats.push({
type: CAVEAT_TYPES.limitResponseLength,
value: 1,
name: CAVEAT_NAMES.primaryAccountOnly,
})

ethAccounts.caveats.push({
type: CAVEAT_TYPES.filterResponse,
value: finalizedAccounts,
name: CAVEAT_NAMES.exposedAccounts,
})
Copy link
Member

@rekmarks rekmarks May 27, 2020

Choose a reason for hiding this comment

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

I want to note for posterity that this order is unfortunately important. Fortunately, it is preserved when we call addPermittedAccount, which calls CapabilitiesController.updateCaveatFor on the exposedAccounts caveat, which adds the updated caveat to the end of the caveat array.

There's currently no way to ensure that rpc-cap enforces a particular order of caveat application, except to add/update them such that they're in the order you desire.

So, happily not a problem here, but I'll create an issue on rpc-cap for a feature request.

Copy link
Member

Choose a reason for hiding this comment

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

@metamaskbot
Copy link
Collaborator

Builds ready [d112e95]
Page Load Metrics (627 ± 61 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30554063
domContentLoaded36176262512661
load36276462712661
domInteractive36076162512661

rekmarks
rekmarks previously approved these changes May 27, 2020
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

test/unit/app/controllers/permissions/mocks.js Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [3e868be]
Page Load Metrics (585 ± 43 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint29743594
domContentLoaded3186645848943
load3206655858943
domInteractive3186645838943

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

Re-approve

@brad-decker brad-decker merged commit 34fb525 into develop May 28, 2020
@brad-decker brad-decker deleted the permissions branch May 28, 2020 03:35
Gudahtt added a commit that referenced this pull request Jun 5, 2020
The "Connected accounts" modal was throwing an exception when
attempting to render an account that has no `lastActive` time. The
component and related selector has been updated to no longer expect
the `lastActive` time to be set.

Prior to #8653 there was a guarantee that all connected accounts had a
`lastActive` time set, as the time would be set on any account returned
from the `eth_requestAccounts` call. But after #8653 only the primary
account was returned, so only the primary account had a `lastActive`
time set.

Fixes #8733
Gudahtt added a commit that referenced this pull request Jun 5, 2020
The "Connected accounts" modal was throwing an exception when
attempting to render an account that has no `lastActive` time. The
component and related selector has been updated to no longer expect
the `lastActive` time to be set.

Prior to #8653 there was a guarantee that all connected accounts had a
`lastActive` time set, as the time would be set on any account returned
from the `eth_requestAccounts` call. But after #8653 only the primary
account was returned, so only the primary account had a `lastActive`
time set.

Fixes #8733
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.

Restrict dapp interaction to primary account
5 participants