MINOR: uri_normalizer: Add a `dotdot` normalizer to http-request normalize-uri
This normalizer merges `../` path segments with the predecing segment, removing
both the preceding segment and the `../`.
Empty segments do not receive special treatment. The `merge-slashes` normalizer
should be executed first.
See GitHub Issue #714.
diff --git a/src/http_act.c b/src/http_act.c
index 2af4d47..7e1829e 100644
--- a/src/http_act.c
+++ b/src/http_act.c
@@ -232,6 +232,23 @@
break;
}
+ case ACT_NORMALIZE_URI_DOTDOT: {
+ const struct ist path = http_get_path(uri);
+ struct ist newpath = ist2(replace->area, replace->size);
+
+ if (!isttest(path))
+ goto leave;
+
+ err = uri_normalizer_path_dotdot(iststop(path, '?'), &newpath);
+
+ if (err != URI_NORMALIZER_ERR_NONE)
+ break;
+
+ if (!http_replace_req_path(htx, newpath, 0))
+ goto fail_rewrite;
+
+ break;
+ }
}
switch (err) {
@@ -297,6 +314,11 @@
rule->action = ACT_NORMALIZE_URI_MERGE_SLASHES;
}
+ else if (strcmp(args[cur_arg], "dotdot") == 0) {
+ cur_arg++;
+
+ rule->action = ACT_NORMALIZE_URI_DOTDOT;
+ }
else {
memprintf(err, "unknown normalizer '%s'", args[cur_arg]);
return ACT_RET_PRS_ERR;