Line | Count | Source |
1 | | #ifndef HEADER_CURL_COOKIE_H |
2 | | #define HEADER_CURL_COOKIE_H |
3 | | /*************************************************************************** |
4 | | * _ _ ____ _ |
5 | | * Project ___| | | | _ \| | |
6 | | * / __| | | | |_) | | |
7 | | * | (__| |_| | _ <| |___ |
8 | | * \___|\___/|_| \_\_____| |
9 | | * |
10 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | | * |
12 | | * This software is licensed as described in the file COPYING, which |
13 | | * you should have received as part of this distribution. The terms |
14 | | * are also available at https://curl.se/docs/copyright.html. |
15 | | * |
16 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | | * copies of the Software, and permit persons to whom the Software is |
18 | | * furnished to do so, under the terms of the COPYING file. |
19 | | * |
20 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | | * KIND, either express or implied. |
22 | | * |
23 | | * SPDX-License-Identifier: curl |
24 | | * |
25 | | ***************************************************************************/ |
26 | | #include "curl_setup.h" |
27 | | |
28 | | #include "llist.h" |
29 | | |
30 | | struct Cookie { |
31 | | struct Curl_llist_node node; /* for the main cookie list */ |
32 | | struct Curl_llist_node getnode; /* for getlist */ |
33 | | char *name; /* <this> = value */ |
34 | | char *value; /* name = <this> */ |
35 | | char *path; /* canonical path */ |
36 | | char *domain; /* domain = <this> */ |
37 | | curl_off_t expires; /* expires = <this> */ |
38 | | unsigned int creationtime; /* time when the cookie was written */ |
39 | | BIT(tailmatch); /* tail-match the domain name */ |
40 | | BIT(secure); /* the 'secure' keyword was used */ |
41 | | BIT(livecookie); /* from a server or API, not a stored file */ |
42 | | BIT(httponly); /* the httponly directive is present */ |
43 | | BIT(prefix_secure); /* secure prefix is set */ |
44 | | BIT(prefix_host); /* host prefix is set */ |
45 | | char buf[1]; /* storage area for |
46 | | name+value+path+domain */ |
47 | | }; |
48 | | |
49 | | /* |
50 | | * Available cookie prefixes, as defined in |
51 | | * draft-ietf-httpbis-rfc6265bis-02 |
52 | | */ |
53 | | #define COOKIE_PREFIX__SECURE (1 << 0) |
54 | | #define COOKIE_PREFIX__HOST (1 << 1) |
55 | | |
56 | 3.29M | #define COOKIE_HASH_SIZE 63 |
57 | | |
58 | | struct CookieInfo { |
59 | | /* linked lists of cookies we know of */ |
60 | | struct Curl_llist cookielist[COOKIE_HASH_SIZE]; |
61 | | curl_off_t next_expiration; /* the next time at which expiration happens */ |
62 | | unsigned int numcookies; /* number of cookies in the "jar" */ |
63 | | unsigned int lastct; /* last creation-time used in the jar */ |
64 | | BIT(running); /* state info, for cookie adding information */ |
65 | | }; |
66 | | |
67 | | /* The maximum sizes we accept for cookies. RFC 6265 section 6.1 says |
68 | | "general-use user agents SHOULD provide each of the following minimum |
69 | | capabilities": |
70 | | |
71 | | - At least 4096 bytes per cookie (as measured by the sum of the length of |
72 | | the cookie's name, value, and attributes). |
73 | | In the 6265bis draft document section 5.4 it is phrased even stronger: "If |
74 | | the sum of the lengths of the name string and the value string is more than |
75 | | 4096 octets, abort these steps and ignore the set-cookie-string entirely." |
76 | | */ |
77 | | |
78 | | /** Limits for INCOMING cookies **/ |
79 | | |
80 | | /* The longest we allow a line to be when reading a cookie from an HTTP header |
81 | | or from a cookie jar */ |
82 | 25.9k | #define MAX_COOKIE_LINE 5000 |
83 | | |
84 | | /* Maximum length of an incoming cookie name or content we deal with. Longer |
85 | | cookies are ignored. */ |
86 | 21.2k | #define MAX_NAME 4096 |
87 | | |
88 | | /* Maximum number of Set-Cookie: lines accepted in a single response. If more |
89 | | such header lines are received, they are ignored. This value must be less |
90 | | than 256 since an unsigned char is used to count. */ |
91 | 48.1k | #define MAX_SET_COOKIE_AMOUNT 50 |
92 | | |
93 | | /** Limits for OUTGOING cookies **/ |
94 | | |
95 | | /* Maximum size for an outgoing cookie line libcurl will use in an http |
96 | | request. This is the default maximum length used in some versions of Apache |
97 | | httpd. */ |
98 | 0 | #define MAX_COOKIE_HEADER_LEN 8190 |
99 | | |
100 | | /* Maximum number of cookies libcurl will send in a single request, even if |
101 | | there might be more cookies that match. One reason to cap the number is to |
102 | | keep the maximum HTTP request within the maximum allowed size. */ |
103 | 0 | #define MAX_COOKIE_SEND_AMOUNT 150 |
104 | | |
105 | | struct Curl_easy; |
106 | | struct connectdata; |
107 | | |
108 | | bool Curl_secure_context(struct Curl_easy *data, const char *host, |
109 | | const size_t hlen); |
110 | | |
111 | | /* |
112 | | * Add a cookie to the internal list of cookies. The domain and path arguments |
113 | | * are only used if the COOKIE_HTTPHEADER bit is set in the flags. |
114 | | */ |
115 | | |
116 | 82.6k | #define COOKIE_HTTPHEADER (1<<0) /* if HTTP header-style line */ |
117 | 14.6k | #define COOKIE_LIVE (1<<1) /* from a server or API */ |
118 | 70.1k | #define COOKIE_SECURE (1<<2) /* connection is over secure origin */ |
119 | 31.3k | #define COOKIE_NOPSL (1<<3) /* skip PSL check */ |
120 | 20.9k | #define COOKIE_NOSESSION (1<<6) /* drop session cookies */ |
121 | | |
122 | | CURLcode Curl_cookie_add(struct Curl_easy *data, |
123 | | struct CookieInfo *ci, |
124 | | const char *lineptr, |
125 | | const char *domain, |
126 | | const char *path, |
127 | | const int flags) WARN_UNUSED_RESULT; |
128 | | CURLcode Curl_cookie_getlist(struct Curl_easy *data, |
129 | | bool *okay, const char *hostp, |
130 | | struct Curl_llist *list) WARN_UNUSED_RESULT; |
131 | | void Curl_cookie_clearall(struct CookieInfo *ci); |
132 | | void Curl_cookie_clearsess(struct CookieInfo *ci); |
133 | | |
134 | | #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES) |
135 | | #define Curl_cookie_list(x) NULL |
136 | | #define Curl_cookie_loadfiles(x, y) CURLE_OK |
137 | | #define Curl_cookie_init() NULL |
138 | | #define Curl_cookie_run(x) Curl_nop_stmt |
139 | | #define Curl_cookie_cleanup(x) Curl_nop_stmt |
140 | | #define Curl_flush_cookies(x, y) Curl_nop_stmt |
141 | | #else |
142 | | void Curl_flush_cookies(struct Curl_easy *data, bool cleanup); |
143 | | void Curl_cookie_cleanup(struct CookieInfo *ci); |
144 | | struct CookieInfo *Curl_cookie_init(void); |
145 | | struct curl_slist *Curl_cookie_list(struct Curl_easy *data); |
146 | | CURLcode Curl_cookie_loadfiles(struct Curl_easy *data, |
147 | | int flags) WARN_UNUSED_RESULT; |
148 | | void Curl_cookie_run(struct Curl_easy *data); |
149 | | #endif |
150 | | |
151 | | #endif /* HEADER_CURL_COOKIE_H */ |