]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: sample: add SMP_USE__MAY_ALIAS to mark fetches returning aliasable contents
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Nov 2026 11:31:41 +0000 (13:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Nov 2026 17:12:23 +0000 (18:12 +0100)
Some sample fetches return contents which may be written in multiple
equivalent forms that are interpreted the same way by the next hop, for
example the path with its %-encoding, its case, or its "/./" and "../"
segments. Matching such contents against a pattern to deny requests is
unreliable, and we'll want to be able to detect such constructs at boot.

This adds SMP_USE__MAY_ALIAS, which is not a source but a property of the
fetched contents. It is placed in the ->use field so that it doesn't
require a new field in all fetch keywords, and since this field is
already or'ed into the ACLs and conditions, it will be possible to
quickly check if a condition involves such a fetch.

The double underscore marks the values which are properties of the
contents and not sources. They're not mapped to any SMP_SRC_* value, so
they're ignored when computing the validity domain. They are allocated
from the topmost bit downwards, leaving all the room to the sources
below, and a build time check verifies that the sources never reach
bit 31.

include/haproxy/sample-t.h
src/sample.c

index 1ad14522b4ba9411e77bad89a7a2253115d90bb4..a7c16c621ecbae4418c45c26ba78f82a630ad17a 100644 (file)
@@ -142,6 +142,16 @@ enum {
        /* This composite one is useful to detect if an http_txn needs to be allocated */
        SMP_USE_HTTP_ANY = SMP_USE_HRQHV | SMP_USE_HRQHP | SMP_USE_HRQBO |
                           SMP_USE_HRSHV | SMP_USE_HRSHP | SMP_USE_HRSBO,
+
+       /* The values below are not sources but properties of the fetched
+        * contents. Their names start with "SMP_USE__" to distinguish them from
+        * the sources. They are not mapped to any SMP_SRC_* value and are thus
+        * ignored when computing the validity domain. They are allocated from
+        * the topmost bit downwards, and the sources must never reach them. They
+        * are or'ed into the ACLs' and conditions' ->use like sources, which
+        * allows to quickly check whether a condition depends on such contents.
+        */
+       SMP_USE__MAY_ALIAS = 1U << 31,  /* contents may be aliased: multiple equivalent forms (eg: %-encoding, case, "/./") */
 };
 
 /* Sample validity is computed from the fetch sources above when keywords
index e5f7343f9f1a4faa1114991406df36bbd06dad0f..877e8e02cab8a10498493a881f519e3ed3fbbece 100644 (file)
@@ -94,6 +94,9 @@ static struct sample_conv_kw_list sample_convs = {
        .list = LIST_HEAD_INIT(sample_convs.list)
 };
 
+/* the sources must never reach the content properties (SMP_USE__*) */
+BUG_ON_STATIC(SMP_SRC_ENTRIES > 31);
+
 const unsigned int fetch_cap[SMP_SRC_ENTRIES] = {
        [SMP_SRC_CONST] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT |
                           SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK |