fix(state): injective fqn encoding, output-file isolation, and name validation - #1075
Open
sam-goodwin wants to merge 1 commit into
Open
fix(state): injective fqn encoding, output-file isolation, and name validation#1075sam-goodwin wants to merge 1 commit into
sam-goodwin wants to merge 1 commit into
Conversation
…ation - encodeFqn now escapes %/_/\ before replacing / with __, making the filename codec injective: foo__bar and foo/bar no longer collide, and a resource named __stack_output__ no longer clobbers the stack output. encodeFqnLegacy keeps the old encoding for read-fallback: get falls back to the legacy filename, set/delete clean it up, so state written by older versions stays readable and migrates on write. - withValidatedNames wraps every backend (local, S3, HTTP client) so stack/stage names that would escape or restructure the store layout (empty, ".", "..", path separators) fail with a typed StateStoreError instead of touching paths outside the store. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Install the packages built from this commit: alchemy bun add alchemy@https://pkg.ing/alchemy/79a4b91@alchemy.run/better-auth bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/79a4b91@alchemy.run/pr-package bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/79a4b91 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the three name-handling weaknesses found while writing the LocalState unit suite (#1072).
Injective fqn codec
encodeFqnescapes%,_, and\before replacing/with__, so every__in a filename is unambiguously a separator:Fqns without
_/%/\— including all/-separated namespaced fqns — produce the same filename as before, so most existing state is read in place. For the rest, the stores fall back and migrate:getfalls back to the legacy filename when the new one is absentsetwrites the new filename and removes the legacy onedeleteremoves bothencodeFqnLegacypreserves the old encoding for that fallback.__stack_output__isolationA resource with fqn
__stack_output__now encodes to its own file (%5F%5Fstack%5Foutput%5F%5F.json) instead of clobbering the stack-output bookkeeping object, and it appears inlist. The legacy fallback explicitly refuses to read or delete the bookkeeping file as a resource.Stack/stage name validation
All backends embed stack/stage as path segments (local directory tree, S3 keys, HTTP routes), where a name like
..escapes the store —deleteStack({ stack: ".." })would have removed.alchemywholesale. A sharedwithValidatedNameswrapper now guards every operation on the local, S3, and HTTP-client stores:The Cloudflare store is covered via the HTTP client;
InMemoryService(test util, plain Map keys) is unwrapped.Compatibility
_/%/\uses the escaped filename, which an older CLI would not find. Same-direction upgrades are unaffected.Covered by 6 new codec tests in
test/FQN.test.tsand 7 new/updated LocalState tests (legacy migration, output-file isolation, validation); verified green against the live S3 and Cloudflare state store suites.🤖 Generated with Claude Code