s[left] = '\0';
}
-/* Resolve /./ and /../ in a URL, in-place. Returns NULL if the URL is
- * invalid/unsafe, or the original buffer if successful.
+/* Resolve /./ and /../ in a URL, in-place. Also strip out query params.
+ * Returns NULL if the URL is invalid/unsafe, or the original buffer if
+ * successful.
*/
static char *make_safe_url(char *url) {
struct {
size_t urllen, i, j, pos;
int ends_in_slash;
- assert(url != NULL);
+ /* strip query params */
+ for (pos=0; url[pos] != '\0'; pos++) {
+ if (url[pos] == '?') {
+ url[pos] = '\0';
+ break;
+ }
+ }
+
if (url[0] != '/')
return NULL;
+
consolidate_slashes(url);
urllen = strlen(url);
if (urllen > 0)
def test_file_get_redundant_dots(self):
self.get_helper("/././." + self.url)
+ def test_file_get_question(self):
+ self.get_helper(self.url + "?")
+
+ def test_file_get_question_query(self):
+ self.get_helper(self.url + "?action=Submit")
+
def test_file_head(self):
resp = Conn().get(self.url, method="HEAD")
status, hdrs, body = parse(resp)
}
static char const *tests[] = {
+ "", NULL,
"/", "/",
"/.", "/",
"/./", "/",
"/a/b/../../../c", NULL,
/* don't forget consolidate_slashes */
"//a///b////c/////", "/a/b/c/",
+ /* strip query params */
+ "/?a=b", "/",
+ "/index.html?", "/index.html",
+ "/index.html?a", "/index.html",
+ "/index.html?a=b", "/index.html",
NULL
};