]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http_ext: add rfc7239_is_valid converter
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 30 Dec 2022 15:23:08 +0000 (16:23 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Jan 2023 14:18:59 +0000 (15:18 +0100)
Adding new http converter: rfc7239_is_valid.

Takes a string representing 7239 forwarded header single value as
input and returns bool:TRUE if header is RFC compliant and
bool:FALSE otherwise.

  Example:
    acl valid req.hdr(forwarded),rfc7239_is_valid
    #input: "for=127.0.0.1;proto=http"
    #  output: TRUE
    #input: "proto=custom"
    #  output: FALSE

Depends on:
  - "MINOR: http_ext: introduce http ext converters"

doc/configuration.txt
src/http_ext.c

index 2d70047f0ca645d5bbfe94dbc2ee6013d41af35a..a40f0903fbaa86eace4af72990663bc4fe177b1c 100644 (file)
@@ -17217,6 +17217,17 @@ The currently available list of transformation keywords include :
       http-request set-header X-51D-DeviceTypeMobileTablet \
         %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)]
 
+rfc7239_is_valid
+  Returns true if input header is RFC 7239 compliant header value and false
+  otherwise.
+
+  Example:
+    acl valid req.hdr(forwarded),rfc7239_is_valid
+    #input: "for=127.0.0.1;proto=http"
+    #  output: TRUE
+    #input: "proto=custom"
+    #  output: FALSE
+
 add(<value>)
   Adds <value> to the input value of type signed integer, and returns the
   result as a signed integer. <value> can be a numeric value or a variable
index 1c621a66a7dd1bfda24ce5666ffbbc8de53638f4..1b899471cbb8bd2b3689146c50f6b6b58408434e 100644 (file)
@@ -1370,8 +1370,22 @@ void http_ext_xot_copy(struct http_ext_xot *dest, const struct http_ext_xot *ori
  * related converters
  */
 
+/* input: string representing 7239 forwarded header single value
+ * does not take arguments
+ * output: 1 if header is RFC compliant, 0 otherwise
+ */
+static int sample_conv_7239_valid(const struct arg *args, struct sample *smp, void *private)
+{
+       struct ist input = ist2(smp->data.u.str.area, smp->data.u.str.data);
+
+       smp->data.type = SMP_T_BOOL;
+       smp->data.u.sint = !!http_validate_7239_header(input, FORWARDED_HEADER_ALL, NULL);
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten */
 static struct sample_conv_kw_list sample_conv_kws = {ILH, {
+       { "rfc7239_is_valid",  sample_conv_7239_valid,   0,                NULL,   SMP_T_STR,  SMP_T_BOOL},
        { NULL, NULL, 0, 0, 0 },
 }};