Repository navigation
fix(sharing): mask the upstream key by char, not byte - #199
Merged
Merged
Conversation
`mask_upstream_key` sliced the key by byte (`&key[..2]` and `&key[key.len() - 4..]`) without a char-boundary check. The key is supplied verbatim by the caller of `POST /api/sharings`, so any multi-byte character straddling byte 2 (or byte `len-4`) panics the handler: panicked at src/routes/sharing.rs:57: end byte index 2 is not a char boundary Masking is now performed over chars; the ASCII output is unchanged (`sk-realsecret1234` -> `sk-****1234`). Adds a regression test covering both the helper and the endpoint.
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.
Summary
POST /api/sharingspanicked on any multi-bytekey.mask_upstream_key(
src/routes/sharing.rs) sliced the key by byte —&key[..2]and&key[key.len() - 4..]— without a char-boundary check. The key is suppliedverbatim by the caller (
sharing::create), so a key such as中中中(9 bytes)or
aa中中(8 bytes) crashes the handler:Masking is now performed over chars; the ASCII output is byte-for-byte
unchanged (
sk-realsecret1234->sk-****1234).The sibling helper
auth::mask_api_keyhas the same shape but only everreceives server-generated keys (
atk_live_+ hex), so it is left untouched.Related Issue
(none — found during internal review)
Changes
mask_upstream_keytruncates by char instead of by byte (src/routes/sharing.rs)Tests
cargo test全部通过 (188 passed; was 187)cargo fmt --check通过mask_upstream_key_is_char_boundary_safe— covers the helper (multi-byte short/long keys + ASCII unchanged) and a realPOST /api/sharingswith a non-ASCII keyChecklist
fix/)