Get value from nested header

Hi

I have a header coming from downstream that looks something like this:
“subjectdn: serialNumber=randomnumbers, ST=someStateOrProvinceName, L=someLocality, C=someCountryName, O=someOrganizationName, OU=someOrganizationalUnit, CN=someCommonName” - so basically some fields from the client TLS certificate. TLS is terminated downstream.

How can I extract the value of sertialNumber? I can get the whole subjectdn with capture.req.hdr(subjectdn) but using it later will just give me the last CN=someCommonName value.

Is it even possible without LUA?

Thanks in advance!

Hello,

not sure what you want to do with the serial. I was able to add a custom header with the serial only with this config :

    http-request set-header X-SERIAL %[req.fhdr(subjectdn),regsub(serialNumber=\"(\d+)\"\"(.*)\",\"\1\")]

Basically, it fetch the subjectdn header then perform a regsub to keep the serial and store it in a new header.

Maybe the regex can be improved to manage some exceptions

1 Like

Thanks, this lead me to the final solution I needed. Instead of a header I use it in variable that will be part of a composite key to identify API clients.