Skip to content

Add SubjectMetadataController - #61

Merged
rekmarks merged 12 commits into
mainfrom
subject-metadata-controller
Nov 25, 2021
Merged

rekmarks merged 12 commits into
mainfrom
subject-metadata-controller

Conversation

@rekmarks

Copy link
Copy Markdown
Contributor

The extension permission metadata functionality is currently housed within its local permissions controller. This PR extracts this functionality into a new "subject" (previously known as "domain") metadata controller, per the extension implementation.

@rekmarks

rekmarks commented Aug 24, 2021 •

Copy link
Copy Markdown
Contributor Author

We should merge this PR into main once the new permissions controller has been merged. Also TBD whether we're going to implement metamask_sendDomainMetadata as part of this PR or do something else with that.

Update: The permission controller has been merged, and we're not going to implement metamask_sendDomainMetadata here.

@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from 8e3db4a to 04bad9b Compare August 24, 2021 07:03
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch from 2339f04 to 1e22d47 Compare August 24, 2021 21:17
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from 6c6562d to 5c059b0 Compare August 24, 2021 21:17
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch 4 times, most recently from dac2e7b to 33ea7e2 Compare September 1, 2021 23:16
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch 2 times, most recently from 6321637 to 828cf30 Compare September 15, 2021 05:13
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch from 21edcf9 to 30cfa77 Compare September 21, 2021 23:13
@rekmarks rekmarks mentioned this pull request Sep 23, 2021
11 tasks done
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch 2 times, most recently from 32353db to 21eb94c Compare September 26, 2021 02:19
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from 5c059b0 to 0f95120 Compare September 27, 2021 04:19
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch from 8484b4e to 9356a65 Compare September 28, 2021 20:44
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch 2 times, most recently from 6a08b84 to 9d9ac05 Compare September 29, 2021 08:31
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch from 0b67125 to fe2ef0e Compare September 29, 2021 20:10
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from 9d9ac05 to c81ae20 Compare September 29, 2021 20:14
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch 4 times, most recently from 9506ac7 to ad34223 Compare October 1, 2021 22:03
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from c81ae20 to 59ec623 Compare October 1, 2021 22:47
@rekmarks
rekmarks force-pushed the permissions-controller-v2 branch from fcc2062 to 4df1d36 Compare October 10, 2021 05:23
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch 2 times, most recently from 7a16930 to b05fd11 Compare October 12, 2021 05:32
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from b05fd11 to c79e82e Compare November 17, 2021 03:55
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from c79e82e to ec614c6 Compare November 24, 2021 00:03
@rekmarks
rekmarks changed the base branch from permissions-controller-v2 to main November 24, 2021 00:04
@rekmarks
rekmarks marked this pull request as ready for review November 24, 2021 00:04
@rekmarks
rekmarks requested a review from Gudahtt November 24, 2021 00:05
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
.values()
.next().value;

this.subjectsEncounteredSinceStartup.delete(cachedOrigin);

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.

So wait.... we're removing the origin from this list, even if we want to preserve the metadata? Why would we let these two data sets get out of sync like that?

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 see that the existing subject metadata controller works basically the same way, and it seems like a bug there as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this is intentional. If a subject encountered since startup has permissions, the current implementation essentially says "screw it, if permissions are ever removed for this subject, we'll let the next subsequent call to trimMetadataState remove it". That'll likely occur at the next reboot of the extension, and that should be good enough for our purposes.

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.

But why keep it around indefinitely if we don't need to? I don't see the advantage to doing this.

If we keep these two collections in sync, and only remove from the set when we remove the actual metadata, we can be confident that the trimming will work correctly and remove any excess metadata without associated permissions. As things stand now it could grow unbounded until the next reset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As things stand now it could grow unbounded until the next reset.

Yes, but since it's been working like this for ~two years, we can be confident that it doesn't grow out of control in practice. The next reset will be no later than the next update, and our update frequency is if anything going to increase as opposed to decrease. As for users that don't update or restart their browsers, I think that's out of scope.

If if we were to implement your suggestion, unbounded growth is still theoretically possible since we never delete metadata for subjects with permissions under any circumstance.

But why keep it around indefinitely if we don't need to? I don't see the advantage to doing this.

There are advantages, though! In your suggested implementation, we would have to iterate over the entire since-startup set if it's larger than the cache limit, check the permissions of each subject, and delete the first one we find without permissions. The unlucky case here is that the user adds permissions to every subject they encounter. In that case, there will eventually be a computational cost to performing this iteration every time the user visits a new website.

In addition, changing how this work can result in a degraded user experience. Consider again the case where the user adds permissions to every subject under your suggested implementation. Let's say, after hitting the cache limit, they visit a new website. By the time we receive a permissions request from that website, its metadata will have been deleted. The only way to add metadata for it and any subsequent new websites would be to accept the request (without metadata) and refresh the page.

This brings me to the final advantage, which is that improving the existing implementation is more complicated than it seems, and probably not worth our time given that the existing implementation demonstrably works in practice. I think the real solution to this problem is to be able to request metadata on demand, which requires the series of changes to json-rpc-engine we've discussed in the past.

@Gudahtt Gudahtt Nov 25, 2021 •

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.

Consider again the case where the user adds permissions to every subject under your suggested implementation. Let's say, after hitting the cache limit, they visit a new website. By the time we receive a permissions request from that website, its metadata will have been deleted. The only way to add metadata for it and any subsequent new websites would be to accept the request (without metadata) and refresh the page.

Ok, fair enough, that makes sense. I still don't like the idea of letting it grow unbounded, and I do not accept the last two years as evidence that this isn't a problem (that does not follow). But you are right that my suggestion is bad and this is more complicated than I thought.

Could we at least rename the variable though? I expected subjectsEncounteredSinceStartup to be the subjects encountered since startup, and was very surprised to find that it was not that at all. Maybe something like subjectsWithoutPermissionsEcounteredSinceStartup? It's absurdly long but it's clear at least. Or subjectsEncounteredWithoutPermissions, since "since startup" is implied as this can't be persisted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in: d4cdb68

Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.ts Outdated
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from 7373a36 to 7a5aa3d Compare November 24, 2021 21:43
@rekmarks
rekmarks force-pushed the subject-metadata-controller branch from ec6a216 to 62a6af4 Compare November 25, 2021 05:00
Comment thread packages/controllers/src/subject-metadata/SubjectMetadataController.test.ts Outdated

@Gudahtt Gudahtt 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!

@rekmarks
rekmarks merged commit 4f09182 into main Nov 25, 2021
@rekmarks
rekmarks deleted the subject-metadata-controller branch November 25, 2021 17:47
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.

2 participants