Skip to content

Ensure HTTPCookie domain matching conforms to RFC6265 #1630

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

Merged
merged 2 commits into from
Jul 31, 2018
Merged

Ensure HTTPCookie domain matching conforms to RFC6265 #1630

merged 2 commits into from
Jul 31, 2018

Conversation

maksimorlovich
Copy link
Contributor

Fix an issue when HTTPCookie domain starts with ".", cookies are
not being sent with HTTP requests. Also, force domain matching to
be in all lower case.

Fix an issue when HTTPCookie domain starts with ".", cookies are
not being sent with HTTP requests. Also, force domain matching to
be in all lower case.
// domain string is a %x2E (".") character.
// * The string is a host name (i.e., not an IP address).

let dotlessDomain = domain.first == "." ? String(domain.suffix(domain.count - 1)) : domain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps domain.hasPrefix(".") ? String(domain.dropFirst()) : domain?

You may also wish to save the result of testing for the prefix since you do use it twice, or refactor to use it once (this can save you from allocating another String too):

guard domain.hasPrefix(".") else { return host == domain }
return host == domain.dropFirst() || host.hasSuffix(domain)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great suggestion. I have updated the code and will push shortly. I also updated unit tests a bit as part of this change.

Thanks!

- Also update unit tests to be more accurate in testing domain matching
@spevans
Copy link
Contributor

spevans commented Jul 13, 2018

@swift-ci please test

@maksimorlovich
Copy link
Contributor Author

Hi. Could this please be merged in? I'd really like to have this in the next release (4.1.3?). Thanks!

@parkera
Copy link
Contributor

parkera commented Jul 24, 2018

Cc'ing a few more people... @ianpartridge @pushkarnk

@ianpartridge
Copy link
Contributor

LGTM, @mamabusi ?

@maksimorlovich
Copy link
Contributor Author

@mamabusi could you please review? I would really like to have this fix in 4.2 Swift release. Thanks!

@mamabusi
Copy link
Contributor

@maksimorlovich Sorry for the delay.
LGTM

@ianpartridge
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 8ebf49c into swiftlang:master Jul 31, 2018
@ianpartridge
Copy link
Contributor

@maksimorlovich can you open a PR against the 4.2 branch so we can get the fix in there too? Thanks!

@maksimorlovich
Copy link
Contributor Author

@ianpartridge what is your process for PR's in 4.2 branch... ie, should I make fresh changes in 4.2 branch and create a PR from my fork, or do a cherry pick from master to 4.2 branch? Thanks!

@ianpartridge
Copy link
Contributor

You should be able to open a new PR that cherry-picks 8ebf49c into swift-4.2-branch :)

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.

7 participants