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

Don't leak RPC objects from API #115679

Closed
jrieken opened this issue Feb 3, 2021 · 8 comments
Closed

Don't leak RPC objects from API #115679

jrieken opened this issue Feb 3, 2021 · 8 comments
Assignees
Labels
api debt Code quality issues engineering VS Code - Build / issue tracking / etc.
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Feb 3, 2021

This is a continuation of #115530 and an effort to make our API implementation more strict/locked-down.

Most of our API is implemented with the help of RPC calls to the renderer - that can be retrieving data or doing something. This is implemented with a protocol instance and objects that represent a slice of the API, aka proxies, like MainThreadTextEditorsShape. These proxies usually mirror the capabilities of the API but are often more powerful and therefore we should make sure these objects cannot be reached from the API.

These leakages usually occur when having an API implemented as object which holds API-properties and internal/private-properties. Since non-native private properties aren't hidden to consumers an extension can reach them.

There are usually two ways of fixing this

  1. Use a native private property - that is a property which name starts with #. Those properties aren't accessible to outsiders but you should know that TypeScript down-level compiles native privates to a construct that uses weak map and is therefore significantly slower. This is a sample commit that hides a proxy by using a native private property: a01d16e
  2. A better approach is to not mix API and implementation into a single class/function-scope but to separate them. c399d03 is a sample for that, instead of mixing things the NotebookEditorDecorationType-type has now a value-property which is the API. All internals are hidden inside the containing class/scope. This has an additional benefit of TypeScript checking that your API isn't too large, e.g when using a literal for a certain API-type then the compiler will check that you have no extra properties. In the sample above having the NotebookEditorDecorationType.value.notDeclaredAPI :string-property yield in a compile error.

To test this I have added the assertNoRpcFromEntry and assertNoRpc utilities which recursively crawl an API object and assert that no RPC object can be reached.

These utilities run during teardown and on objects the API creates, like a status bar entry item. The checking for leaked RPC object does depend therefore on test coverage.

@jrieken
Copy link
Member Author

jrieken commented Feb 3, 2021

There are a tests that are skipped because they would be failing. Assigning folks

@jrieken jrieken added the debt Code quality issues label Feb 3, 2021
@bpasero bpasero removed their assignment Feb 3, 2021
@chrmarti chrmarti removed their assignment Feb 5, 2021
@RMacfarlane RMacfarlane assigned rebornix and unassigned RMacfarlane May 13, 2021
@jrieken
Copy link
Member Author

jrieken commented Jun 9, 2021

ping @eamodio

@jrieken
Copy link
Member Author

jrieken commented Jun 9, 2021

ping @rebornix

@jrieken
Copy link
Member Author

jrieken commented Jul 5, 2021

ping @eamodio @rebornix

@rebornix rebornix added this to the July 2021 milestone Jul 5, 2021
rebornix added a commit that referenced this issue Jul 5, 2021
@rebornix
Copy link
Member

rebornix commented Jul 5, 2021

finished the comment API part. At the beginning I was marking proxy as real private properties but it will still expose non-API methods like eventuallyUpdateCommentThread. To ensure we only expose methods declared in API, a value property suggested above is clean and perfect. @eamodio you may want to do the same for ExtHostSourceControl as it has public functions which are out of the scope of API.

This is a nice pattern to have, thanks for bringing this up @jrieken ❤️ .

@rebornix rebornix removed their assignment Jul 5, 2021
@alexr00 alexr00 modified the milestones: July 2021, August 2021 Jul 30, 2021
@jrieken jrieken modified the milestones: August 2021, September 2021 Aug 23, 2021
@jrieken jrieken removed this from the September 2021 milestone Sep 17, 2021
@jrieken jrieken added api engineering VS Code - Build / issue tracking / etc. labels Oct 11, 2021
jrieken added a commit that referenced this issue Dec 7, 2021
sourcegraph-bot pushed a commit to sgtest/megarepo that referenced this issue Dec 7, 2021
Commit: 5c31535ea8e984e249351f9fa56fb4990040cd61
@lszomoru
Copy link
Member

SCM fixed with 85694fc

@lszomoru
Copy link
Member

@jrieken, do you want to keep the issue opened, or can we go ahead and close it?

@lszomoru lszomoru removed their assignment Dec 20, 2021
@jrieken
Copy link
Member Author

jrieken commented Dec 20, 2021

Thanks @lszomoru This can be closed 👯 I have added a few more tests recently but didn't find further RPC leaks. There are likely some more left but we can handle them case by case.

@jrieken jrieken closed this as completed Dec 20, 2021
@jrieken jrieken added this to the January 2022 milestone Dec 20, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api debt Code quality issues engineering VS Code - Build / issue tracking / etc.
Projects
None yet
Development

No branches or pull requests

8 participants