Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Disallow plugins from changing the teamID #381

Merged
merged 4 commits into from
May 13, 2021
Merged

Disallow plugins from changing the teamID #381

merged 4 commits into from
May 13, 2021

Conversation

neilkakkar
Copy link
Contributor

@neilkakkar neilkakkar commented May 12, 2021

Closes #363

Added a WIP walthrough section, describing how everything works together in plugin-server.

I'll fix the "stream of consciousness" sections in the README before I merge. Corrections welcome.

Checklist

  • Updated Settings section in README.md, if settings are affected
  • Jest tests

@neilkakkar neilkakkar requested a review from yakkomajuri May 12, 2021 14:46
Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

Super awesome the docs you put out, absolutely great!

RE the actual task, LGTM. I'd generally avoid having a try catch for a user-defined throw, but I think it makes sense in this case.

I'm happy to merge as is. Do wonder though about an approach where we don't even expose team ID to plugins, therefore preventing plugin devs from shooting themselves in the foot by changing a prop that was indeed exposed to them.

Nevertheless, great stuff!

@@ -44,7 +44,8 @@ export async function runOnSnapshot(server: PluginsServer, event: PluginEvent):
}

export async function runProcessEvent(server: PluginsServer, event: PluginEvent): Promise<PluginEvent | null> {
const pluginsToRun = getPluginsForTeam(server, event.team_id)
const team_id = event.team_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'd follow JS camelCase convention even if the prop uses snake_case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh, how did I not notice everything else using JS camelCase lol. A python habit xD - is there a specific style guide we're following?

@@ -57,6 +58,10 @@ export async function runProcessEvent(server: PluginsServer, event: PluginEvent)

try {
returnedEvent = (await processEvent(returnedEvent)) || null
if (returnedEvent.team_id != team_id) {
returnedEvent = null // don't try to ingest events with modified teamIDs
throw new Error('Changing team IDs is an illegal operation')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can we devise an error message that will be more informative to a user of the plugin? Since plugin logs errors will now pop up on the UI so it'd be nice to do something like "Illegal operation: plugin tried to change team ID"

@neilkakkar
Copy link
Contributor Author

Do wonder though about an approach where we don't even expose team ID to plugins, therefore preventing plugin devs from shooting themselves in the foot by changing a prop that was indeed exposed to them.

I was thinking about this too, and it felt very messy? Since plugins are inserted into the middle of the data flow, any data you remove needs to be managed outside the plugins: say, something like, the vm removes some event properties we don't want the users to see, or better yet, we remove it ourselves inside runProcessEvent() before sending the event, and add it back after we receive the event.

This was also a bit annoying, since some plugins might actually want to read these properties, for whatever reason, and then it becomes a question of exposing a readonly interface.

At that point, I figured it was just easier to validate if no illegal operations occurred.

Definitely worth revisiting though, if we have a lot of fields like these.

@neilkakkar neilkakkar added the bump patch Bump patch version when this PR gets merged label May 13, 2021
@neilkakkar neilkakkar merged commit 877cbd2 into master May 13, 2021
@neilkakkar neilkakkar deleted the teamid branch May 13, 2021 09:40
fuziontech pushed a commit to PostHog/posthog that referenced this pull request Oct 12, 2021
…ugin-server#381)

* add code walkthrough and prevent changing team IDs in plugins
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins that change team_id
2 participants