-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Iterate on toolbar iframe message passing and api endpoint doma…
…in (#81942) Related to getsentry/sentry-toolbar#142 This moves the `request-login` and `request-logout` messages back into the window.postMessage handler, and reserves the MessageChannel and ports for logged-in api traffic only. Overall the code is reorganized to better make the 3 message event listeners clearer: - `did-login` event listener on the window. Guarded to only accept messages from the same domain as this page is on (aka, from sentry itself). This is how the cookie/token gets moved around. - `request-login` & `request-logout` event listener on the window. A separate handler that guards for messages from the `referrerOrigin` only. The referrer should also be the same as window.parent.location.origin, but we can't query for that value directly. - `MessageChannel` ports event listener. This is only setup after the server has validated login, and checked project permissions. The ports are setup using `postMessage(..., referrerOrigin)` where `referrerOrigin` was validated on the server and passed back from the server, so we're very sure that we're setting up the MessageChannel against the correct domain only. These three concerns are split up, and there's some extra code to make things more explicit. For example, we have explicit `handleXYZ()` methods that have some copy+pasted delegation code inside. This is intentionally separate from the `const fooMessageDispatch = {...}` objects as these dispatchers make it easier to see which commands or events are supported by each handler. I've also injected `regionUrl` into the template, so the `fetch` command doesn't rely on the SDK setting the correct sentry api domain. Instead we can prefix api requets with the correct domain, and at the same time insert the cookie/token value to the request. This means that tokens/cookies will not be sent to any domain other than `regionUrl`, which is set by the server. [This diagram](https://www.mermaidchart.com/play?utm_source=mermaid_js&utm_medium=banner_ad&utm_campaign=teams#pako:eNqlU7FuwjAQ_RWLJUGQQDsilamdSiWkDl1YTHxN3Sa2azswlP57z7GbhhAEFAnkJPfu3d17569BJhkMZgMDnxWIDO45zTUtV4IQRbXlGVdUWPJ8_0iocUc3wl8RDi448Y9dQCFzLup4_bQSDkArK0VVrkG7N8eezOfunBEuuI2H7rOGzBKdr2k8HRP83U7dmd7UwSZrFFqYESazqgRhU6oUCBYHXOjQFfhFbrlgcptSxh42mLDgxoIAHUclGENziMbkjQpWwMK1_FKjn3xoSK5nXVKN8RO0iZcjkKo6JVXS2JARG0st7GvhUxg3iIOl1EFIFCPIXlhSp92hFzmwRFbWE5zQukdtf6aZFLYZZq-_SLudMjapfY8apr8RR345miEl2hZHkw7eL1CtSEdphwe9X5RxFgqOSSblB4eDwsn8cGU81KQGbHwk7QxLIhS3gKgr2hFbGkR7iTQkSMv8xWhZB4WB4B0XG1rgmErLd2fbbtcJMFlSlKz5Hszm4kyvr3UbtypqkfVcFQbFgfZ9CRcrfo7mZ6lOOqJfqmFr6FMjKOwuQWUFcuLWutdhx_3_XFDHs1cIHTq-1D1oo9ptNIf7D75_AInT_g4) might be helpful for reviewers. It shows the interactions between the SDK, this `/iframe/` page, and the `/login-success/` page which emits the `did-login` message. It was tough to express in that sequence diagram the guards that are in place, i'll have to draw up another one with that info. What is shown are - the 2 messages that can come in from the SDK: `request-login` and `request-logout` - the 1 message from the `/login-success/` page: `did-login` - the `port-connect` system, which happens only after `state=logged-in` - when a state change is required, we emit the `stale` event and rely on the SDK to reload this iframe page. Internal state like that never mutates, we take state from the server at all times.
- Loading branch information
Showing
2 changed files
with
141 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters