question

GertVloo avatar image
0 Votes"
GertVloo asked MikeUrnun answered

Bug in API Management set-header policy when using UTF-8 characters

Hi, I think I found a bug in APIM set-header policy.

When I use a UTF-8 'dash' (–) character as input for set-header I get the error: "Expression value is invalid. Specified value has invalid Control characters."

The first error is thrown at 11-6-2021 07:01:04.722Z

Are there more people having this problem?

azure-api-management
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @GertVloo - I'd like to reproduce and validate. Could you share the policy snippet you used and any repro steps that might help?

0 Votes 0 ·

Hi Mike,

Here is the simplified policy I used:


  <inbound>
         <set-variable name="requestBody" value="@{return context.Request.Body.As<string>(preserveContent: true);}" />
         <set-variable name="CUSTOMER_STATUS" value="@{return System.Xml.XPath.Extensions.XPathSelectElements(XDocument.Parse((string)context.Variables["requestBody"]), "//CONTACT_LOG_DETAIL[ATTRIBUTE='CUSTOMER_STATUS']/VALUE").FirstOrDefault()?.Value;}" />
         <set-header name="CUSTOMER_STATUS" exists-action="override">
             <value>@(context.Variables.GetValueOrDefault<string>("CUSTOMER_STATUS")?.ToUpper())</value>
         </set-header>
     </inbound>

And here is the test request:

         <CONTACT_LOG>
             <CONTACT_LOG_DETAILS>
                 <CONTACT_LOG_DETAIL>
                     <ATTRIBUTE>CUSTOMER_STATUS</ATTRIBUTE>
                     <VALUE>HOLD 108 – OK</VALUE>
                 </CONTACT_LOG_DETAIL>
             </CONTACT_LOG_DETAILS>
         </CONTACT_LOG>
0 Votes 0 ·

Thanks, @GertVloo! I'll review and get back to you with my findings.

1 Vote 1 ·

1 Answer

MikeUrnun avatar image
0 Votes"
MikeUrnun answered

Hello @GertVloo

I have run this by the APIM team and they have confirmed that this is not a bug but an expected behavior that honors the RFC2616 spec for the header value as *TEXT, which is an 8-bit sequence of data excluding control characters: https://datatracker.ietf.org/doc/html/rfc2616#page-16

I hope this brings clarity and helps you proceed with your project.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.