-
Notifications
You must be signed in to change notification settings - Fork 232
[eas-cli] carry the serve-sim session token in simulator preview links #4312
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,19 @@ export function getRemoteSessionEnvironmentVariables( | |
|
|
||
| type RemoteSessionInstructionsConfigType = 'env' | 'dotenv'; | ||
|
|
||
| /** | ||
| * Preview link for a session. A gated serve-sim needs the session token, and a browser cannot send | ||
| * a header on a page load, so it rides the query. serve-sim swaps it for a cookie on the first load. | ||
| */ | ||
| export function formatPreviewUrl(url: string, token: string | null | undefined): string { | ||
| if (!token) { | ||
| return url; | ||
| } | ||
| const withToken = new URL(url); | ||
| withToken.searchParams.set('token', token); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow up idea: What if the URL would carry a distinct, least-privilege credential - ideally a short-lived, one-time bootstrap token exchanged for a secure cookie. Browser controls should authorize only typed simulator operations, never arbitrary commands. We are also planning to move streaming to expo.dev so we should also plan having it in mind. |
||
| return withToken.toString(); | ||
| } | ||
|
|
||
| export function formatRemoteSessionInstructions( | ||
| remoteConfig: DeviceRunSessionRemoteConfig, | ||
| configType: RemoteSessionInstructionsConfigType | ||
|
|
@@ -112,7 +125,7 @@ export function formatRemoteSessionInstructions( | |
| '', | ||
| '🌐 Open the following URL in your browser to preview the simulator:', | ||
| '', | ||
| remoteConfig.webPreviewUrl | ||
| formatPreviewUrl(remoteConfig.webPreviewUrl, remoteConfig.webPreviewToken) | ||
| ); | ||
| } | ||
| return lines.join('\n'); | ||
|
|
@@ -150,7 +163,7 @@ export function formatRemoteSessionInstructions( | |
| '', | ||
| '🌐 Open the following URL in your browser to preview the simulator:', | ||
| '', | ||
| remoteConfig.webPreviewUrl | ||
| formatPreviewUrl(remoteConfig.webPreviewUrl, remoteConfig.webPreviewToken) | ||
| ); | ||
| } | ||
| return lines.join('\n'); | ||
|
|
@@ -174,21 +187,26 @@ export function formatRemoteSessionInstructions( | |
| '<appium-client> [args...]', | ||
| ]; | ||
| if (remoteConfig.webPreviewUrl) { | ||
| lines.push('', 'Open the simulator preview:', '', remoteConfig.webPreviewUrl); | ||
| lines.push( | ||
| '', | ||
| 'Open the simulator preview:', | ||
| '', | ||
| formatPreviewUrl(remoteConfig.webPreviewUrl, remoteConfig.webPreviewToken) | ||
| ); | ||
| } | ||
| return lines.join('\n'); | ||
| } | ||
| case 'ServeSimRunSessionRemoteConfig': | ||
| return [ | ||
| '🌐 Open the following URL in your browser to access the simulator:', | ||
| '', | ||
| remoteConfig.previewUrl, | ||
| formatPreviewUrl(remoteConfig.previewUrl, remoteConfig.previewToken), | ||
| ].join('\n'); | ||
| case 'WebPreviewOnlyRunSessionRemoteConfig': | ||
| return [ | ||
| '🌐 Open the following URL in your browser to access the simulator:', | ||
| '', | ||
| remoteConfig.previewUrl, | ||
| formatPreviewUrl(remoteConfig.previewUrl, remoteConfig.previewToken), | ||
| ].join('\n'); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Format and sanitize gated preview data in JSON output too
Both
eas simulator --jsonandeas simulator get --jsonserializeremoteConfigdirectly, bypassingformatPreviewUrl. A gated session therefore returns a barepreviewUrl/webPreviewUrlthat responds with 401, alongside the bearer token as a separate field.Please produce a sanitized JSON remote config whose preview URL has passed through
formatPreviewUrland omit the standalone preview token. Alternatively, explicitly document and test JSON output as a separate low-level{ url, token }contract.