From: Willy Tarreau Date: Wed, 11 Nov 2026 11:31:41 +0000 (+0200) Subject: MINOR: sample: add SMP_USE__MAY_ALIAS to mark fetches returning aliasable contents X-Git-Tag: v3.5-dev12~14 X-Git-Url: https://git.kaiwu.me/%7B@url%7D?a=commitdiff_plain;h=b5cfeb14524ee38b171ac41fdd3244d9907e9f95;p=haproxy.git MINOR: sample: add SMP_USE__MAY_ALIAS to mark fetches returning aliasable contents 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. --- diff --git a/include/haproxy/sample-t.h b/include/haproxy/sample-t.h index 1ad14522b..a7c16c621 100644 --- a/include/haproxy/sample-t.h +++ b/include/haproxy/sample-t.h @@ -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 diff --git a/src/sample.c b/src/sample.c index e5f7343f9..877e8e02c 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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 |