@cryptotaxi247 / netdata-1 / commits / 65583beda

Fix redirect with parameters

Netdata was missing query string when there was redirect, this PR fixes this.

thiagoftsm committed Aug 28, 2020 at 13:00 UTC 65583beda30d71ae51a440abf59c9ca2ab468466
1 file changed +34 -32
web/server/web_client.c
+34 -32
@@ -1084,6 +1084,10 @@ static inline HTTP_VALIDATION http_request_validate(struct web_client *w) {
1084 if ((w->ssl.conn) && ((w->ssl.flags & NETDATA_SSL_NO_HANDSHAKE) && (web_client_is_using_ssl_force(w) || web_client_is_using_ssl_default(w)) && (w->mode != WEB_CLIENT_MODE_STREAM)) ) {
1085 w->header_parse_tries = 0;
1086 w->header_parse_last_size = 0;
1087 + // The client will be redirected for Netdata and we are preserving the original request.
1088 + *ue = '\0';
1089 + strncpyz(w->last_url, encoded_url, NETDATA_WEB_REQUEST_URL_SIZE);
1090 + *ue = ' ';
1091 web_client_disable_wait_receive(w);
1092 return HTTP_VALIDATION_REDIRECT;
1093 }
@@ -1158,39 +1162,30 @@ void web_client_build_http_header(struct web_client *w) {
1162 strftime(edate, sizeof(edate), "%a, %d %b %Y %H:%M:%S %Z", tm);
1163 }
1164
1161 - char headerbegin[8328];
1165 if (w->response.code == HTTP_RESP_MOVED_PERM) {
1163 - memcpy(headerbegin,"\r\nLocation: https://",20);
1164 - size_t headerlength = strlen(w->server_host);
1165 - memcpy(&headerbegin[20],w->server_host,headerlength);
1166 - headerlength += 20;
1167 - size_t tmp = strlen(w->last_url);
1168 - memcpy(&headerbegin[headerlength],w->last_url,tmp);
1169 - headerlength += tmp;
1170 - memcpy(&headerbegin[headerlength],"\r\n",2);
1171 - headerlength += 2;
1172 - headerbegin[headerlength] = 0x00;
1166 + buffer_sprintf(w->response.header_output,
1167 + "HTTP/1.1 %d %s\r\n"
1168 + "Location: https://%s%s\r\n",
1169 + w->response.code, code_msg,
1170 + w->server_host,
1171 + w->last_url);
1172 }else {
1174 - memcpy(headerbegin,"\r\n",2);
1175 - headerbegin[2]=0x00;
1176 - }
1177 -
1178 - buffer_sprintf(w->response.header_output,
1179 - "HTTP/1.1 %d %s\r\n"
1180 - "Connection: %s\r\n"
1181 - "Server: NetData Embedded HTTP Server %s\r\n"
1182 - "Access-Control-Allow-Origin: %s\r\n"
1183 - "Access-Control-Allow-Credentials: true\r\n"
1184 - "Content-Type: %s\r\n"
1185 - "Date: %s%s"
1186 - , w->response.code, code_msg
1187 - , web_client_has_keepalive(w)?"keep-alive":"close"
1188 - , VERSION
1189 - , w->origin
1190 - , content_type_string
1191 - , date
1192 - , headerbegin
1193 - );
1173 + buffer_sprintf(w->response.header_output,
1174 + "HTTP/1.1 %d %s\r\n"
1175 + "Connection: %s\r\n"
1176 + "Server: NetData Embedded HTTP Server %s\r\n"
1177 + "Access-Control-Allow-Origin: %s\r\n"
1178 + "Access-Control-Allow-Credentials: true\r\n"
1179 + "Content-Type: %s\r\n"
1180 + "Date: %s\r\n",
1181 + w->response.code,
1182 + code_msg,
1183 + web_client_has_keepalive(w)?"keep-alive":"close",
1184 + VERSION,
1185 + w->origin,
1186 + content_type_string,
1187 + date);
1188 + }
1189
1190 if(unlikely(web_x_frame_options))
1191 buffer_sprintf(w->response.header_output, "X-Frame-Options: %s\r\n", web_x_frame_options);
@@ -1583,7 +1578,14 @@ void web_client_process_request(struct web_client *w) {
1578 {
1579 buffer_flush(w->response.data);
1580 w->response.data->contenttype = CT_TEXT_HTML;
1586 - buffer_strcat(w->response.data, "<!DOCTYPE html><!-- SPDX-License-Identifier: GPL-3.0-or-later --><html><body onload=\"window.location.href ='https://'+ window.location.hostname + ':' + window.location.port + window.location.pathname\">Redirecting to safety connection, case your browser does not support redirection, please click <a onclick=\"window.location.href ='https://'+ window.location.hostname + ':' + window.location.port + window.location.pathname\">here</a>.</body></html>");
1581 + buffer_strcat(w->response.data,
1582 + "<!DOCTYPE html><!-- SPDX-License-Identifier: GPL-3.0-or-later --><html>"
1583 + "<body onload=\"window.location.href ='https://'+ window.location.hostname +"
1584 + " ':' + window.location.port + window.location.pathname + window.location.search\">"
1585 + "Redirecting to safety connection, case your browser does not support redirection, please"
1586 + " click <a onclick=\"window.location.href ='https://'+ window.location.hostname + ':' "
1587 + " + window.location.port + window.location.pathname + window.location.search\">here</a>."
1588 + "</body></html>");
1589 w->response.code = HTTP_RESP_MOVED_PERM;
1590 break;
1591 }