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

HttpRequest::cookies assumes percent-encoding and fails if one cookie is not #3542

Open
lennart-k opened this issue Jan 4, 2025 · 0 comments

Comments

@lennart-k
Copy link

lennart-k commented Jan 4, 2025

Current Behavior

Currently HttpRequest::cookies assumes that all cookie are percent-encoded and returns an error if at least one cookie is not percent-encoded and contains invalid character sequences for that encoding, e.g. (%db).

Possible Solution

Given that changing the default to non-percent-encoded cookies might not be a good idea,
and that HttpRequest::cookies() does some caching in HttpRequest::extensions()
I would propose implementing a HttpRequest::cookies_lossy() function that just collects all the cookies it can and that can then be used by HttpRequest::cookie(name).

Steps to Reproduce (for bugs)

Example:

use actix_web::{http::header, test::TestRequest};

fn main() {
    let req = TestRequest::get()
        .insert_header((header::COOKIE, "asd=hello other_actually_valid_cookie=%db"))
        .to_http_request();
    dbg!(req.cookies().unwrap()); // Err(Utf8Error)
    dbg!(req.cookie("asd")); // None
}
  • Here, req.cookies() fails, hence req.cookie("asd") also returns nothing.

Context

In my use case I also have a session cookie from Authelia, which may contain such sequences,
which seem valid to me (see RFC 6265 4.1.1).
Although I don't want to parse that cookie it still prevents me from parsing the cookie for actix-session.

Your Environment

  • Rust Version: 1.83.0
  • Actix Web Version: 4.9.0
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

1 participant