Browse Source

Introduce mg_request_info::local_uri_raw which contains the URI in un-cleaned form.

Signed-off-by: DL6ER <dl6er@dl6er.de>
DL6ER 4 years ago
parent
commit
45cb2d7b9b
2 changed files with 20 additions and 1 deletions
  1. 5 1
      include/civetweb.h
  2. 15 0
      src/civetweb.c

+ 5 - 1
include/civetweb.h

@@ -151,9 +151,13 @@ struct mg_request_info {
 	const char *request_method;  /* "GET", "POST", etc */
 	const char *request_uri;     /* URL-decoded URI (absolute or relative,
 	                              * as in the request) */
-	const char *local_uri;       /* URL-decoded URI (relative). Can be NULL
+	char *local_uri_raw;         /* URL-decoded URI (relative). Can be NULL
 	                              * if the request_uri does not address a
 	                              * resource at the server host. */
+	const char *local_uri;       /* Same as local_uri_raw, however, cleaned
+	                              * so a path like
+	                              *   allowed_dir/../forbidden_file
+	                              * is not possible */
 #if defined(MG_LEGACY_INTERFACE) /* 2017-02-04, deprecated 2014-09-14 */
 	const char *uri;             /* Deprecated: use local_uri instead */
 #endif

+ 15 - 0
src/civetweb.c

@@ -14086,6 +14086,7 @@ handle_request(struct mg_connection *conn)
 
 	/* 1.4. clean URIs, so a path like allowed_dir/../forbidden_file is
 	 * not possible */
+	ri->local_uri_raw = mg_strdup(ri->local_uri);
 	remove_dot_segments((char *)ri->local_uri);
 
 	/* step 1. completed, the url is known now */
@@ -16816,6 +16817,13 @@ reset_per_request_attributes(struct mg_connection *conn)
 	conn->request_info.request_uri = NULL;
 	conn->request_info.local_uri = NULL;
 
+	/* Free local URI in raw form (if any) */
+	if(conn->request_info.local_uri_raw != NULL)
+	{
+		mg_free(conn->request_info.local_uri_raw);
+		conn->request_info.local_uri_raw = NULL;
+	}
+
 #if defined(MG_LEGACY_INTERFACE)
 	/* Legacy before split into local_uri and request_uri */
 	conn->request_info.uri = NULL;
@@ -18973,6 +18981,13 @@ worker_thread_run(struct mg_connection *conn)
 	mg_free(conn->buf);
 	conn->buf = NULL;
 
+	/* Free local URI in raw form (if any) */
+	if(conn->request_info.local_uri_raw != NULL)
+	{
+		mg_free(conn->request_info.local_uri_raw);
+		conn->request_info.local_uri_raw = NULL;
+	}
+
 #if defined(USE_SERVER_STATS)
 	conn->conn_state = 9; /* done */
 #endif