Skip to content

refactor(middleware): handle URI parsing safely in cookie and redirect services - #3088

Open
spellsaif wants to merge 1 commit into
seanmonstar:masterfrom
spellsaif:refactor/uri-parsing-panic-prevention
Open

refactor(middleware): handle URI parsing safely in cookie and redirect services#3088
spellsaif wants to merge 1 commit into
seanmonstar:masterfrom
spellsaif:refactor/uri-parsing-panic-prevention

Conversation

@spellsaif

Copy link
Copy Markdown
Contributor

Safely handle http::Uri to reqwest::Url parsing in CookieService and TowerRedirectPolicy, eliminating potential .expect() panic sites on invalid or relative URIs.

Motivation & Problem

CookieService and TowerRedirectPolicy used .expect("invalid URL") when converting req.uri() or redirect previous targets. If custom Tower stacks pass origin-form or relative URIs (e.g. /api/v1/resource), Url::parse returns Err(RelativeUrlWithoutBase), causing an unexpected library panic.

Solution

  • In CookieService: Safely convert req.uri() with .ok(). If req.uri() is relative, gracefully skip cookie header insertion and cookie response extraction for that request without panicking.
  • In TowerRedirectPolicy: Return Err(crate::error::builder(e)) instead of panicking on invalid URLs.

Testing

  • cargo check --features cookies passes cleanly.

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

Successfully merging this pull request may close these issues.

1 participant