Repository navigation
fix: return 404 for directory paths exceeding the KV key limit - #1100
Draft
DebasishKaran-1 wants to merge 2 commits into
Draft
DebasishKaran-1 wants to merge 2 commits into
DebasishKaran-1 wants to merge 2 commits into
Conversation
Add a check for maximum key length in readDirectory method Signed-off-by: DebasishKaran-1 <Kalyanikaran1234@gmail.com>
Signed-off-by: DebasishKaran-1 <Kalyanikaran1234@gmail.com>
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.
Closes #1049.
Workers KV rejects keys longer than 512 UTF-8 bytes. When a malformed request arrives with a path longer than that (as captured by Sentry in #1049),
KvProvider.readDirectorytries to look it up in KV, KV responds with414 UTF-8 encoded length ... exceeds key length limit of 512, and the error propagates.As suggested in the issue, such a path cannot exist as a file or directory, so it can be rejected proactively:
readDirectorynow returnsundefined(which leads to a 404) without hitting KV or R2 when the UTF-8 encoded path exceeds 512 bytes.Changes:
src/providers/kvProvider.ts: byte-length guard at the top ofreadDirectory, usingTextEncoderso multi-byte characters are measured by bytes, not characters.src/providers/kvProvider.test.ts: regression tests covering an over-limit ASCII path, an over-limit multi-byte path (171 three-byte characters = 513 bytes but only 171 characters), and a path exactly at the 512-byte limit which is still looked up.Validation:
tsc --noEmit, and Prettier all pass locally.This change was prepared with AI assistance and is submitted with the account owner's approval.