@cryptotaxi247 / netdata-1 / commits / 51b57dc0a

Add new cookie to fix 8094 (#10676)

Add missing cookies to Netdata.

thiagoftsm committed Mar 2, 2021 at 20:00 UTC 51b57dc0a5997cc8203ede0a7e67884c0ef72a34
4 files changed +30 -2
registry/README.md
+11
@@ -176,6 +176,17 @@ There can be up to 2 files:
176
177 Both files are machine readable text files.
178
179 +### How can I disable the SameSite and Secure cookies?
180 +
181 +Beginning with `v1.30.0`, when the Netdata Agent's web server processes a request, it delivers the `SameSite=none`
182 +and `Secure` cookies. If you have problems accessing the local Agent dashboard or Netdata Cloud, disable these
183 +cookies by [editing `netdata.conf`](/docs/configure/nodes.md#use-edit-config-to-edit-configuration-files):
184 +
185 +```conf
186 +[registry]
187 + enable cookies SameSite and Secure = no
188 +```
189 +
190 ## The future
191
192 The registry opens a whole world of new possibilities for Netdata. Check here what we think:
registry/registry.c
+17 -2
@@ -23,7 +23,7 @@ static inline void registry_unlock(void) {
23 // COOKIES
24
25 static void registry_set_cookie(struct web_client *w, const char *guid) {
26 - char edate[100];
26 + char edate[100], domain[512];
27 time_t et = now_realtime_sec() + registry.persons_expiration;
28 struct tm etmbuf, *etm = gmtime_r(&et, &etmbuf);
29 strftime(edate, sizeof(edate), "%a, %d %b %Y %H:%M:%S %Z", etm);
@@ -31,7 +31,22 @@ static void registry_set_cookie(struct web_client *w, const char *guid) {
31 snprintfz(w->cookie1, NETDATA_WEB_REQUEST_COOKIE_SIZE, NETDATA_REGISTRY_COOKIE_NAME "=%s; Expires=%s", guid, edate);
32
33 if(registry.registry_domain && registry.registry_domain[0])
34 - snprintfz(w->cookie2, NETDATA_WEB_REQUEST_COOKIE_SIZE, NETDATA_REGISTRY_COOKIE_NAME "=%s; Domain=%s; Expires=%s", guid, registry.registry_domain, edate);
34 + snprintfz(domain, 511, "Domain=%s", registry.registry_domain);
35 + else
36 + domain[0]='\0';
37 +
38 + int length = snprintfz(w->cookie2, NETDATA_WEB_REQUEST_COOKIE_SIZE,
39 + NETDATA_REGISTRY_COOKIE_NAME "=%s; Expires=%s; %s",
40 + guid, edate, domain);
41 +
42 + size_t remaining_length = NETDATA_WEB_REQUEST_COOKIE_SIZE - length;
43 + // 25 is the necessary length to add new cookies
44 + if (registry.enable_cookies_samesite_secure) {
45 + if (length > 0 && remaining_length > 25)
46 + snprintfz(&w->cookie2[length], remaining_length, "; SameSite=None; Secure");
47 + else
48 + error("Netdata does not have enough space to store cookies SameSite and Secure");
49 + }
50 }
51
52 static inline void registry_set_person_cookie(struct web_client *w, REGISTRY_PERSON *p) {
registry/registry_init.c
+1
@@ -39,6 +39,7 @@ int registry_init(void) {
39 registry.registry_to_announce = config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io");
40 registry.hostname = config_get(CONFIG_SECTION_REGISTRY, "registry hostname", netdata_configured_hostname);
41 registry.verify_cookies_redirects = config_get_boolean(CONFIG_SECTION_REGISTRY, "verify browser cookies support", 1);
42 + registry.enable_cookies_samesite_secure = config_get_boolean(CONFIG_SECTION_REGISTRY, "enable cookies SameSite and Secure", 1);
43
44 registry_update_cloud_base_url();
45 setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1);
registry/registry_internals.h
+1
@@ -40,6 +40,7 @@ struct registry {
40 char *cloud_base_url;
41 time_t persons_expiration; // seconds to expire idle persons
42 int verify_cookies_redirects;
43 + int enable_cookies_samesite_secure;
44
45 size_t max_url_length;
46 size_t max_name_length;