Repository navigation
fix: allow commands from within endpoints - #14343
Conversation
🦋 Changeset detectedLatest commit: 4b4de69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
d1be925 to
45e6ef9
Compare
Rich-Harris
left a comment
There was a problem hiding this comment.
I'm not sure this is quite right — surely we want to allow commands in POST requests etc, but not in GET/HEAD?
|
Are you suggesting that SvelteKit should not let developers use certain remote functions inside certain endpoints because of opinions? |
For what technical reason? |
|
RFC 9110 on HTTP semantics says this:
|
|
So no technical reason but spec reason. I'm fine looking into adjusting this, just wanted to clarify |
implemented endpoint method check for commands
* fix: allow commands from within endpoints fixes sveltejs#14325 * limit commands to post/put/patch/delete * fix * tweak --------- Co-authored-by: Rich Harris <[email protected]>
Fixes #17739 Command endpoints parse JSON before checking the request method. Empty GET requests therefore become unexpected SyntaxErrors with status 500, while valid payloads can even execute commands through PUT/PATCH/DELETE. The dispatcher switch from #15991 retained the form and query.batch method guards, but commands only had the wrapper's restrictions. That wrapper runs after deserialization and intentionally permits mutative methods for server-side calls, as established by #14343 and #15288. Restricting the wrapper to POST would both miss the parsing failure and break those supported calls. Add the neighboring POST-only SvelteKitError guard at the start of command dispatch, making non-POST bodies unable to reach parsing or execution. All generated command endpoints use this handler in dev and production, regardless of adapter. `query` and `prerender` endpoints had no method check either and ran for any method, so they now only accept GET. `query.live`, `query.batch` and `form` already had their checks; non-enhanced forms are unchanged. This preserves the remote protocol: runtime errors remain HTTP 200 envelopes with the error status inside the payload, following #14365. The rejection is now a framework error with status 405 and message `Method Not Allowed`, rather than an unknown SyntaxError. It still passes through handleError, as intended by #16664. - Ported reproduction: [SvelteLab](https://www.sveltelab.dev/#code=N4IgzgTgxiBcoBMCWECmUAuB7CBPOoAhgA7EB0AFhgLYA2BIAZkrag1FgHYardhwgAPAEIEWTLmKoABFToA%2BADqdBc2tNqFOAcwC8ikLw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Vn5AgppwNIBiGaQYRY1wOMGA0iJRXp9qsBAADy%2BpIFwtMEuTYwGGiuqYAYBIYBA763FynMtPBPgVDL0gANoS9A7P0yAKQSdjSC4ylIAALqo617UykOsryvjnCE2qxOjVqYvZFMqAawYgIBAMADsAcAMwAJzs5zcJgELph0wYAAMZCJ0MIAcxTIDAkgSQphrcvvmntggOiUg%2ByAgYIDG3up5zFUi%2BpiLZBUSSl4bMhNxHFPZJB2Ut20Mjd7QCAd%2BLGdoCk6S99WwKVKkaTD1E2TTzKaCl5tPABICqJoVABiKwXjeVAAIqgUj0bwUCpHXHuFxtoU7WEVgkDwEABJwbxVwSBgAGxJ2QKf7zfNeqB76AlLsHP%2Bf956ALvrtVuARcQ%2BG0C0X4SoP76wDmQAATEnKB2QgGlwAKxkAIRgzBuCZiSAFFAXU%2BpS4-0TsHchBs%2B6lyCGQcBjCQCKytk7dqrcyDG1NoNWSI1FJalWmpR%2B%2BoTJnj0p6W%2BqD75SOfq-d%2B5lWiqWtBlIBm8dLng9Ao7au19qt3URIrRtoKjMEsguTgOMnSyP0qYnMygrI2U%2BKgRghACIeOsagWxONUwewQUgzgYACSax0W0IJ0g3EmRUusToos8JVlQAAMR8OhdowtZbyxkFyR8XxpHLUKU-Eybl2SZktpwSp6NORAA). <!-- svelte-triage-bot:feedback-baseline:3b2af5050a905f6a0b9f1cdf291ed7d7291a32fb --> --------- Co-authored-by: svelte-triage-bot <[email protected]> Co-authored-by: Tee Ming <[email protected]>
fixes #14325
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.