Skip to content

Execute Playground code on a separate origin #285

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

Merged
merged 6 commits into from
Apr 9, 2021
Merged

Conversation

aomarks
Copy link
Member

@aomarks aomarks commented Apr 8, 2021

Fixes #26

Why

We want to execute Playground code on a separate origin, so that scripts are completely isolated from the main origin. In particular, scripts loaded through the "share" feature are not controlled by us, and often are written by another user to the person running it.

On a site that has access to e.g. sensitive user data or APIs on the main origin, this would be very important for security. That's why Playground warns in the console when it detects same-origin execution.

Our site is 100% static, so there's pretty limited risks -- an attacker could e.g. modify some page content, navigate the main window, etc. If we did something like integrate with GitHub gists for shorter Playground URLs, then an attacker might then be able to make authenticated GitHub requests through shared Playground code. So it seems like a good idea to close this hole before launch.

How

  1. We have a new Cloud Run service called lit-dev-playground. Its URL is https://lit-dev-playground-5ftespv5na-uc.a.run.app/, and PR revisions have the same pr<PR>-<SHA> prefix that the main service has. When we go live, the URL will be https://playground.lit.dev

  2. When we do an Eleventy build, the PLAYGROUND_SANDBOX environment variable is rendered into the HTML everywhere we instantiate a <playground-ide> or <playground-project> using the sandbox-base-url attribute. This attribute tells Playground to interact with a Service Worker at that URL, instead of the default one on the same origin.

  3. The server has a new MODE environment variable switch. When it's set to playground, it only serves the js/ directory, instead of the full site. It uses the same Docker image, so this shouldn't affect build time much -- just a bit of extra time to deploy two services.

@aomarks aomarks force-pushed the playground-domain branch 3 times, most recently from def6033 to de26055 Compare April 8, 2021 01:34
@aomarks aomarks changed the title [DO NOT REVIEW] WIP Playground domain [DO NOT REVIEW] Execute Playground code on a separate origin Apr 8, 2021
@aomarks aomarks force-pushed the playground-domain branch from 07eaf26 to 9528090 Compare April 8, 2021 01:47
@aomarks aomarks requested a review from sorvell April 8, 2021 01:48
@aomarks aomarks changed the title [DO NOT REVIEW] Execute Playground code on a separate origin Execute Playground code on a separate origin Apr 8, 2021
@aomarks aomarks marked this pull request as ready for review April 8, 2021 01:49
@github-actions
Copy link

github-actions bot commented Apr 8, 2021

A live preview of this PR will be available at the URL(s) below.
The latest URL will be appended to this comment on each push.
Each build takes ~5-10 minutes, and will 404 until finished.

https://pr285-b20be7c---lit-dev-5ftespv5na-uc.a.run.app/

Copy link
Member

@sorvell sorvell left a comment

Choose a reason for hiding this comment

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

LGTM. Not familiar with any of this code so just reviewed for obvious red flags.

@aomarks aomarks merged commit ad7b5ec into master Apr 9, 2021
@aomarks aomarks deleted the playground-domain branch April 9, 2021 18:45
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.

Setup second origin for playground
2 participants