@cryptotaxi247 / netdata-1 / commits / 1db77eb15

Restrict quotes in label values (#7594)

* quotes_labels: Restrict quotes This commit brings the restriction for the values that will not be allowed to have quotes * quotes_labels: Documentation This commit brings update to the documentation * quotes_labels: Missing comma This commit brings a missing comma for the documentation * quotes_labels: Rename variable The variable was renamed to let code more readable * quotes_labels: call function There was a missing call in our utf-8 function, this commit fixes this * quotes_labels: Remove segmentation fault The previous code could result in a segmentation fault depending of the label size, this commit removes this possibility * quotes_labels: remove unecessary UTF-8 Considering that I am testing all addresses, I am removing the UTf-8 call * quotes_labels: Rename variable This commit renames variable according to documentation * quotes_labels: Comparison to function this commit converts the comparison to test labels to an unique function * quotes_labels: Restore name The new name was breaking compatibility with the structure value * quotes_labels: Rename function Rename the function to keep an unique pattern * quotes_labels: Restore previous utf-8 library * quotes_labels: Remove missing file * quotes_labels: Fix grammar Fix grammar documentation * quotes_labels: Missing comparison This commit brings the two missing characters that must be rejected from value * quotes_labels: Fix grammar again Fix grammar documentation

thiagoftsm committed Jan 16, 2020 at 14:31 UTC 1db77eb15e802ffb111300a1a20c0fcdfa26d6e7
2 files changed +21 -5
database/rrdhost.c
+19 -4
@@ -710,6 +710,18 @@ void rrdhost_save_charts(RRDHOST *host) {
710 rrdhost_unlock(host);
711 }
712
713 +static int is_valid_label_value(char *value) {
714 + while(*value) {
715 + if(*value == '"' || *value == '\'' || *value == '*' || *value == '!') {
716 + return 0;
717 + }
718 +
719 + value++;
720 + }
721 +
722 + return 1;
723 +}
724 +
725 static int is_valid_label_key(char *key) {
726 //Prometheus exporter
727 if(!strcmp(key, "chart") || !strcmp(key, "family") || !strcmp(key, "dimension"))
@@ -784,6 +796,10 @@ struct label *load_auto_labels()
796 return label_list;
797 }
798
799 +static inline int is_valid_label_config_option(char *name, char *value) {
800 + return (is_valid_label_key(name) && is_valid_label_value(value) && strcmp(name, "from environment") && strcmp(name, "from kubernetes pods") );
801 + }
802 +
803 struct label *load_config_labels()
804 {
805 int status = config_load(NULL, 1, CONFIG_SECTION_HOST_LABEL);
@@ -798,13 +814,12 @@ struct label *load_config_labels()
814 config_section_wrlock(co);
815 struct config_option *cv;
816 for(cv = co->values; cv ; cv = cv->next) {
801 - char *name = cv->name;
802 - if(is_valid_label_key(name) && strcmp(name, "from environment") && strcmp(name, "from kubernetes pods") ) {
803 - l = add_label_to_list(l, name, cv->value, LABEL_SOURCE_NETDATA_CONF);
817 + if( is_valid_label_config_option(cv->name, cv->value)) {
818 + l = add_label_to_list(l, cv->name, cv->value, LABEL_SOURCE_NETDATA_CONF);
819 cv->flags |= CONFIG_VALUE_USED;
820 } else {
821 error("LABELS: It was not possible to create the label '%s' because it contains invalid character(s) or values."
807 - , name);
822 + , cv->name);
823 }
824 }
825 config_section_unlock(co);
docs/configuration-guide.md
+2 -1
@@ -143,7 +143,8 @@ restrictions are applied for label names:
143 - Names cannot start with `_`, but it can be present in other parts of the name.
144 - Names only accept alphabet letters, numbers, dots, and dashes.
145
146 -The policy for values are more flexible, but you can not use exclamation (`!`), whitespaces (` `) and asterisk (`*`),
146 +The policy for values is more flexible, but you can not use exclamation marks (`!`), whitespaces (` `), single quotes (`'`),
147 +double quotes (`"`), or asterisks (`*`),
148 because they are used to compare label values in health alarms and templates.
149
150 [![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fdocs%2Fconfiguration-guide&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)