Skip to content

Add origin as query string to requests to plotlyServerURL#7854

Open
marthacryan wants to merge 2 commits into
masterfrom
add-newchart-query-string
Open

Add origin as query string to requests to plotlyServerURL#7854
marthacryan wants to merge 2 commits into
masterfrom
add-newchart-query-string

Conversation

@marthacryan

@marthacryan marthacryan commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

For secure communication between tabs via postMessage (after clicking the "upload to cloud" button), we need to include the origin of the request as a query string.

Comment thread src/plots/plots.js Outdated
Comment on lines +218 to +221
var uploadUrl = serverURL +
(serverURL.indexOf('?') === -1 ? '?' : '&') +
'origin=' + encodeURIComponent(window.location.origin);
var cloudWindow = window.open(uploadUrl, '_blank');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@marthacryan Is there any built-in JS utility for handling URL params that we could use here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

^ ah yeah that looks right, or the URL API more broadly. I think the most thorough logic would be:

  • parse serverURL into its base URL plus params
  • add origin: window.location.origin to params dict
  • re-generate full URL with new params

I suppose we could also just strip URL parameters from serverURL entirely since we don't currently have a use for them... but that might not even be any simpler.

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.

@emilykl Good point! How does the updated code look?

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.

3 participants