Skip to content

Don't fetch when loading the config property - #440

Merged
augustjk merged 4 commits into
mainfrom
restrict-untrusted-config
Nov 24, 2026
Merged

augustjk merged 4 commits into
mainfrom
restrict-untrusted-config

Conversation

@augustjk

@augustjk augustjk commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Setting the config property on <playground-ide> or <playground-project> used to fetch any file listed without content, follow extends, and adopt cdnBaseUrl from the config. config is the documented way to load a shared project, so a config from an untrusted source could make the host page fetch arbitrary URLs with the user's credentials and expose the responses to code running in the preview.

Changes

  • config no longer fetches project files or other manifests. Only files with inline content and the importMap are used. Files without content, extends, and cdnBaseUrl are dropped with a console warning. project-src is unchanged.
  • config has its own type, ProjectConfig, which requires content on every file and has no extends or cdnBaseUrl. The runtime handling stays for configs parsed from JSON.
  • Typings for import map URLs are fetched without credentials, so an untrusted import map can't make the host page send authenticated requests.

Breaking changes

This needs a 0.22.0 release.

  • Configs that relied on fetched files, extends or cdnBaseUrl must be loaded with project-src, with the CDN set through the cdnBaseUrl property or cdn-base-url attribute.
  • TypeScript callers that assign a ProjectManifest to config, or set the removed fields in a literal, no longer compile.
  • Typings that can only be fetched with credentials no longer load.

@augustjk
augustjk added this pull request to stack #439 November 18, 2026 19:09
@augustjk
augustjk requested a review from rictic November 18, 2026 19:30
Base automatically changed from release-v0-21-3 to main November 19, 2026 17:27
Setting the `config` property on <playground-ide> or <playground-project>
used to fetch any file listed without `content`, follow `extends`, and
adopt `cdnBaseUrl` from the config. The `config` property is the
documented way to load a shared project, so a config from an untrusted
source (e.g. decoded from a URL) could make the host page fetch arbitrary
URLs with the user's credentials. The responses became project files,
which code running in the preview could then read.

The `config` property now only uses files with inline string `content`
and the `importMap`. Files without `content`, `extends`, and `cdnBaseUrl`
are ignored with a console warning, and malformed file entries are
skipped instead of throwing. Manifests loaded with `project-src` are
unchanged.

BREAKING CHANGE: configs set through the `config` property that rely on
fetched files, `extends`, or `cdnBaseUrl` must be loaded with
`project-src` instead, with the CDN set through the `cdnBaseUrl` property
or `cdn-base-url` attribute.
@augustjk
augustjk force-pushed the restrict-untrusted-config branch from 361e884 to ce7f4eb Compare November 19, 2026 17:27
Comment thread src/shared/worker-api.ts Resolved
The config property now has its own type, ProjectConfig, instead of ProjectManifest. It requires inline content for every file and has no extends or cdnBaseUrl, which the setter does not support. Setting them in a config object literal is now a compile error in TypeScript, rather than only a console warning at runtime.

The runtime handling stays, because configs parsed from JSON bypass the type. ProjectManifest goes back to describing only manifests loaded with project-src.

The README and changelog now describe the config format in its own terms, and say that these are not allowed rather than ignored.
The TypeScript worker fetched typings for import map URLs with the page's credentials. An import map from an untrusted config could use that to make the host page send authenticated requests to URLs of its choosing. Fetch them with credentials: 'omit' instead.

Typings that can only be fetched with credentials will no longer load.

Also stop overstating what loading a config guarantees. A code comment, the console warning, the README's sharing FAQ and a test comment said or implied that it never makes the page fetch anything, but a project can still make the worker fetch modules from the CDN and fetch typings. Say what it does guarantee: loading a config does not fetch the files or manifests it names, and the config cannot change the CDN. Likewise, a test used a fetch-marker URL for cdnBaseUrl without checking for fetches. That check could not work, because CDN fetches happen in the worker, so use a plain URL.
The field now only ever holds the CDN base URL of a manifest loaded with project-src, since a config can no longer set one. Rename it and fix its comment.

Also test that the value does not carry over when config is set after project-src.
@augustjk
augustjk merged commit 89fe131 into main Nov 24, 2026
15 of 16 checks passed
@augustjk
augustjk deleted the restrict-untrusted-config branch November 24, 2026 05:04
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.

2 participants