Skip to content

security: Stop automatically adding URLs from server-side load fetch calls to dependencies - #9945

Merged
Rich-Harris merged 12 commits into
masterfrom
elliott/9803-security-remove-implicit-dep-tracking
May 17, 2023
Merged

security: Stop automatically adding URLs from server-side load fetch calls to dependencies#9945
Rich-Harris merged 12 commits into
masterfrom
elliott/9803-security-remove-implicit-dep-tracking

Conversation

@elliott-with-the-longest-name-on-github

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented May 16, 2023

Copy link
Copy Markdown
Contributor

Closes #9803. This is a breaking change for security purposes.

This PR prevents server load function from implicitly depending on URLs passed to fetch. This is because dependencies from server load functions have to be sent to the client in order to be invalidated, which can leak secrets (if they're in the search params, for example).

If you understand the risk and want to keep the old behavior, you can set config.kit.dangerZone.trackServerFetchesPotentiallyExposingSecrets to true.

TODO:

  • Tests
  • Docs

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot

changeset-bot Bot commented May 16, 2023

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 487aa22

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/kit/types/index.d.ts Outdated
Comment on lines +347 to +351
/**
* Automatically add server-side `fetch`ed URLs to the `dependencies` map of `load` functions. This will expose secrets
* to the client if your URL contains them.
*/
trackServerFetchesPotentiallyExposingSecrets?: boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can trim the option name down to trackServerFetches — we can explain the details in the inline documentation, and the dangerZone makes it clear that this is 'know what you're doing' territory

Suggested change
/**
* Automatically add server-side `fetch`ed URLs to the `dependencies` map of `load` functions. This will expose secrets
* to the client if your URL contains them.
*/
trackServerFetchesPotentiallyExposingSecrets?: boolean;
/**
* Mark server `load` functions that call `fetch(url)` as depending on `url`, allowing you to
* call `invalidate(url)` from the client. The URL, including e.g. sensitive query parameters,
* will be visible to the client. This option will be removed in version 2; use `depends` instead
*/
trackServerFetches?: boolean;

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.

I dunno, I like explicitly requiring users to acknowledge what they're doing -- there's no guarantee they understand why this is dangerous. Happy to make the change, but I personally think the annoyance of typing a gigantic and explicit config value is worth it, especially since it's not going to be around forever.

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.

Secrets exposed in server only load fetch dependencies

2 participants