Skip to content

fix: use RFC 6265 path matching for cookie path option#1114

Open
UlisesGascon wants to merge 3 commits intomasterfrom
fix/rfc6265-path-matching
Open

fix: use RFC 6265 path matching for cookie path option#1114
UlisesGascon wants to merge 3 commits intomasterfrom
fix/rfc6265-path-matching

Conversation

@UlisesGascon
Copy link
Copy Markdown
Member

Main Changes

  • Fix session middleware activating on unintended paths (e.g., /admin matching /administrator)
  • Implement RFC 6265 section 5.1.4 path-match algorithm for cookie path comparison
  • Replace simple indexOf prefix check with segment-boundary-aware matching
  • Document RFC 6265 5.1.4 compliance in cookie.path section of README, noting the change since 1.19.1 and the prior behavior

Notes

The previous implementation used originalPath.indexOf(cookiePath) === 0 which matched any path starting with the cookie path string, regardless of segment boundaries. Per RFC 6265 section 5.1.4, a cookie-path should only match if the request-path is identical, or the cookie-path is a prefix followed by a / character.

This is a semver-patch change. It corrects a bug in path matching behavior without changing the public API. Applications using correctly segmented paths (e.g., /admin matching /admin/users) are unaffected. Only the unintended matching of non-segment-boundary paths (e.g., /admin matching /administrator) is corrected.

@metadust
Copy link
Copy Markdown

Happy to help!

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.

2 participants