Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_COOKIES_COOKIE_DELETION_INFO_H_ |
| 6 | #define NET_COOKIES_COOKIE_DELETION_INFO_H_ |
| 7 | |
| 8 | #include <set> |
| 9 | #include <string> |
| 10 | |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 11 | #include "base/time/time.h" |
| 12 | #include "net/cookies/canonical_cookie.h" |
Lily Chen | cdd577712 | 2019-10-14 20:45:54 | [diff] [blame] | 13 | #include "net/cookies/cookie_constants.h" |
Dylan Cutler | 108a4192 | 2022-01-05 18:16:23 | [diff] [blame] | 14 | #include "net/cookies/cookie_partition_key_collection.h" |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 15 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 16 | |
| 17 | namespace net { |
| 18 | |
| 19 | // Used to specify which cookies to delete. All members are ANDed together. |
| 20 | struct NET_EXPORT CookieDeletionInfo { |
| 21 | // TODO(cmumford): Combine with |
| 22 | // network::mojom::CookieDeletionSessionControl. |
| 23 | enum SessionControl { |
| 24 | IGNORE_CONTROL, |
| 25 | SESSION_COOKIES, |
| 26 | PERSISTENT_COOKIES, |
| 27 | }; |
| 28 | |
| 29 | // Define a range of time from [start, end) where start is inclusive and end |
| 30 | // is exclusive. There is a special case where |start| == |end| (matching a |
| 31 | // single time) where |end| is inclusive. This special case is for iOS that |
| 32 | // will be removed in the future. |
| 33 | // |
| 34 | // TODO(crbug.com/830689): Delete the start=end special case. |
| 35 | class NET_EXPORT TimeRange { |
| 36 | public: |
| 37 | // Default constructor matches any non-null time. |
| 38 | TimeRange(); |
| 39 | TimeRange(const TimeRange& other); |
| 40 | TimeRange(base::Time start, base::Time end); |
| 41 | TimeRange& operator=(const TimeRange& rhs); |
| 42 | |
| 43 | // Is |time| within this time range? |
| 44 | // |
| 45 | // Will return true if: |
| 46 | // |
| 47 | // |start_| <= |time| < |end_| |
| 48 | // |
| 49 | // If |start_| is null then the range is unbounded on the lower range. |
| 50 | // If |end_| is null then the range is unbounded on the upper range. |
| 51 | // |
| 52 | // Note 1: |time| cannot be null. |
| 53 | // Note 2: If |start_| == |end_| then end_ is inclusive. |
| 54 | // |
| 55 | bool Contains(const base::Time& time) const; |
| 56 | |
| 57 | // Set the range start time. Set to null (i.e. Time()) to indicated an |
| 58 | // unbounded lower range. |
| 59 | void SetStart(base::Time value); |
| 60 | |
| 61 | // Set the range end time. Set to null (i.e. Time()) to indicated an |
| 62 | // unbounded upper range. |
| 63 | void SetEnd(base::Time value); |
| 64 | |
| 65 | // Return the start time. |
| 66 | base::Time start() const { return start_; } |
| 67 | |
| 68 | // Return the end time. |
| 69 | base::Time end() const { return end_; } |
| 70 | |
| 71 | private: |
| 72 | // The inclusive start time of this range. |
| 73 | base::Time start_; |
| 74 | // The exclusive end time of this range. |
| 75 | base::Time end_; |
| 76 | }; |
| 77 | |
| 78 | CookieDeletionInfo(); |
| 79 | CookieDeletionInfo(CookieDeletionInfo&& other); |
| 80 | CookieDeletionInfo(const CookieDeletionInfo& other); |
| 81 | CookieDeletionInfo(base::Time start_time, base::Time end_time); |
| 82 | ~CookieDeletionInfo(); |
| 83 | |
| 84 | CookieDeletionInfo& operator=(CookieDeletionInfo&& rhs); |
| 85 | CookieDeletionInfo& operator=(const CookieDeletionInfo& rhs); |
| 86 | |
| 87 | // Return true if |cookie| matches all members of this instance. All members |
| 88 | // are ANDed together. For example: if the |cookie| creation date is within |
| 89 | // |creation_range| AND the |cookie| name is equal to |name|, etc. then true |
| 90 | // will be returned. If not false. |
| 91 | // |
cfredric | 571a108 | 2020-11-18 18:07:37 | [diff] [blame] | 92 | // |params.access_semantics| is the access semantics mode of the cookie at the |
| 93 | // time of the attempted match. This is used to determine whether the cookie |
Lily Chen | cdd577712 | 2019-10-14 20:45:54 | [diff] [blame] | 94 | // matches a particular URL based on effective SameSite mode. (But the value |
| 95 | // should not matter because the CookieOptions used for this check includes |
| 96 | // all cookies for a URL regardless of SameSite). |
| 97 | // |
cfredric | 571a108 | 2020-11-18 18:07:37 | [diff] [blame] | 98 | // |params.delegate_treats_url_as_trustworthy| should be set to true if |url| |
| 99 | // was granted access to secure cookies by the CookieAccessDelegate. |
Maks Orlovich | bd04d78 | 2020-11-17 21:23:34 | [diff] [blame] | 100 | // |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 101 | // All members are used. See comments above other members for specifics |
| 102 | // about how checking is done for that value. |
Lily Chen | cdd577712 | 2019-10-14 20:45:54 | [diff] [blame] | 103 | bool Matches(const CanonicalCookie& cookie, |
cfredric | 571a108 | 2020-11-18 18:07:37 | [diff] [blame] | 104 | const CookieAccessParams& params) const; |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 105 | |
| 106 | // See comment above for TimeRange::Contains() for more info. |
| 107 | TimeRange creation_range; |
| 108 | |
| 109 | // By default ignore session type and delete both session and persistent |
| 110 | // cookies. |
| 111 | SessionControl session_control = SessionControl::IGNORE_CONTROL; |
| 112 | |
| 113 | // If has a value then cookie.Host() must equal |host|. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 114 | absl::optional<std::string> host; |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 115 | |
| 116 | // If has a value then cookie.Name() must equal |name|. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 117 | absl::optional<std::string> name; |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 118 | |
| 119 | // If has a value then will match if the cookie being evaluated would be |
| 120 | // included for a request of |url|. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 121 | absl::optional<GURL> url; |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 122 | |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 123 | // If this is not empty then any cookie with a domain/ip contained in this |
| 124 | // will be deleted (assuming other fields match). |
| 125 | // Domains must not have a leading period. e.g "example.com" and not |
| 126 | // ".example.com". |
| 127 | // |
| 128 | // Note: |domains_and_ips_to_ignore| takes precedence. For example if this |
| 129 | // has a value of ["A", "B"] and |domains_and_ips_to_ignore| is ["B", "C"] |
| 130 | // then only "A" will be deleted. |
| 131 | std::set<std::string> domains_and_ips_to_delete; |
| 132 | |
| 133 | // If this is not empty then any cookie with a domain/ip contained in this |
| 134 | // will be ignored (and not deleted). |
| 135 | // Domains must not have a leading period. e.g "example.com" and not |
| 136 | // ".example.com". |
| 137 | // |
| 138 | // See precedence note above. |
| 139 | std::set<std::string> domains_and_ips_to_ignore; |
| 140 | |
| 141 | // Used only for testing purposes. |
Anton Bikineev | 068d291 | 2021-05-15 20:43:52 | [diff] [blame] | 142 | absl::optional<std::string> value_for_testing; |
Dylan Cutler | 108a4192 | 2022-01-05 18:16:23 | [diff] [blame] | 143 | |
Dylan Cutler | 70af880 | 2022-05-24 17:14:38 | [diff] [blame] | 144 | // Cookie partition collection. Partitioned cookies are not deleted if their |
| 145 | // partition key is not in the collection. By default, it clears cookies in |
| 146 | // all partitions. |
Dylan Cutler | 108a4192 | 2022-01-05 18:16:23 | [diff] [blame] | 147 | CookiePartitionKeyCollection cookie_partition_key_collection = |
| 148 | CookiePartitionKeyCollection::ContainsAll(); |
Dylan Cutler | 72ac5509 | 2023-03-20 20:54:05 | [diff] [blame^] | 149 | |
| 150 | // If true, third-party cookie blocking applies to the context that triggered |
| 151 | // the deletion. In this case, we should only delete partitioned cookies. |
| 152 | bool partitioned_state_only = false; |
Chris Mumford | d8ed9f8 | 2018-05-01 15:43:13 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | } // namespace net |
| 156 | |
| 157 | #endif // NET_COOKIES_COOKIE_DELETION_INFO_H_ |