Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when verifying malformed signed cookie #178

Closed
5225225 opened this issue Jul 14, 2021 · 2 comments
Closed

Panic when verifying malformed signed cookie #178

5225225 opened this issue Jul 14, 2021 · 2 comments

Comments

@5225225
Copy link

5225225 commented Jul 14, 2021

reproduction:

fn main() {
    let data = "x=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy£";

    let c = cookie::Cookie::parse(data).expect("failed to parse cookie");

    let key = cookie::Key::from(&[0u8; 64]);

    let mut jar = cookie::CookieJar::new();

    let signed = jar.signed_mut(&key);

    signed.verify(c).expect("failed to verify cookie");
}

stack trace:

thread 'main' panicked at 'byte index 44 is not a char boundary; it is inside '£' (bytes 43..45) of `yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy£`', /rustc/952fdf2a1119affa1b37bcacb0c49cf9f0168ac8/library/core/src/str/mod.rs:576:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/952fdf2a1119affa1b37bcacb0c49cf9f0168ac8/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/952fdf2a1119affa1b37bcacb0c49cf9f0168ac8/library/core/src/panicking.rs:92:14
   2: core::str::slice_error_fail
   3: core::str::<impl str>::split_at
             at /rustc/952fdf2a1119affa1b37bcacb0c49cf9f0168ac8/library/core/src/str/mod.rs:576:13
   4: cookie::secure::signed::SignedJar<J>::_verify
             at /home/jess/.cargo/git/checkouts/cookie-rs-9c795d75da5c954b/0de451d/src/secure/signed.rs:57:35
   5: cookie::secure::signed::SignedJar<J>::verify
             at /home/jess/.cargo/git/checkouts/cookie-rs-9c795d75da5c954b/0de451d/src/secure/signed.rs:94:28
   6: scratchQVE5xNE9W::main
             at ./src/main.rs:12:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/952fdf2a1119affa1b37bcacb0c49cf9f0168ac8/library/core/src/ops/function.rs:227:5

Tested on 0de451d as well as 0.15.0 from crates.io

@SergioBenitez
Copy link
Member

Turns out split_at for a string and split_at for a Vec panic for different reasons. Bummer. Pushing a fix immediately.

@SergioBenitez
Copy link
Member

Published in 0.15.1.

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

No branches or pull requests

2 participants