question

siebeverschaeve avatar image
9 Votes"
siebeverschaeve asked MayankBargali-MSFT edited

[BUG] Azure API Management - validate-content

Hi, During the switch in our project of backend validation to Azure API-Management JSON validate-content we encountered a bug. When the request body includes a datetime such as "timestamp":"2020-06-19T12:54:40.180Z" the trailing 0 milliseconds are being truncated/trimmed.

  • 2020-06-19T12:54:40.180Z becomes 2020-06-19T12:54:40.18Z

  • 2020-06-19T12:54:40.100Z becomes 2020-06-19T12:54:40.1Z

  • 2020-06-19T12:54:40.000Z becomes 2020-06-19T12:54:40Z

Our project applies a strict format yyyy-MM-dd'T'HH:mm:ss.SSS'Z' so none of our implementations expect missing milliseconds nor do our 3rd parties when we forward events (JSON payloads) Rewriting the body (set-body policy) with the following expression does not fix the DateTime parsing. I'm sure that there is DateTime parsing ongoing when the validate-content policy is executed. The parsing needs to be an option.

Can someone give me some insights either on how to resolve it or confirm this is an ongoing bug.

 <set-header name="Content-Type" exists-action="override">
     <value>application/json</value>
 </set-header>
 <set-body>@{ var body = context.Request.Body.AsJObject(true,new JsonSerializerSettings() { DateParseHandling = DateParseHandling.None }); return JsonConvert.SerializeObject(body); }</set-body>
 <validate-content unspecified-content-type-action="prevent" max-size="128" size-exceeded-action="ignore" errors-variable-name="validname">
     <content type="application/json" validate-as="json" action="prevent" />
 </validate-content>


References:
- https://github.com/Azure/API-Management/releases/tag/release-service-2020-10
- validation-policies


Out of scope: I'm sure that the same bug happens whenever you send JSON timestamps through an eventgrid. Thanks to all from the community for participating.








azure-api-managementazure-event-grid
· 2
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.

Hi anonymous user

Welcome to Microsoft Q&A! Thanks for posting the question.
I am reviewing it and will reach out to my team if needed. Will update you once I have further update from my end.

Update:
I have reached out to my team and will keep you posted.

2 Votes 2 ·

anonymous user Product team is working on this and they would also need the openapi schema. Can you please refer to my private comment.

1 Vote 1 ·

1 Answer

MayankBargali-MSFT avatar image
1 Vote"
MayankBargali-MSFT answered MayankBargali-MSFT edited

Product team have fixed the issue and this changes will be included in the next release, which will likely start rolling out in July and finish in late July or in August.

Updated: The issue is fixed now.

· 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.

Thanks a lot, Mayank!

Do you have any idea whether the option could be disabled/optional on Event-Grid as well?
I'm specifically speaking about the Logic App adapter/connector since through c# or other native code it can be disabled through jsonserializersettings.

Can you forward me to the correct team/people if not?
I believe it's trivial from an ISO DateTime point of view.

From microsoft documentation eventgrid (EventGridDeserializer)

 Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
    
 The consumer parses the event time property into a Date object, for ease of use.
 When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded and returned as an instance of the Uint8Array type.





0 Votes 0 ·

Hi @MayankBargali-MSFT ,

I can confirm this has been fixed on API Managements latest release.
Thanks for including my bug resolution.

Would you have had the time to reach out to someone from the Azure event-grid team?
The same exact bug can be replayed while passing events through the grid on logic apps.

  • 2020-06-19T12:54:40.180Z becomes 2020-06-19T12:54:40.18Z

  • 2020-06-19T12:54:40.100Z becomes 2020-06-19T12:54:40.1Z

  • 2020-06-19T12:54:40.000Z becomes 2020-06-19T12:54:40Z

I believe it would be trivial for someone to have the option to enable/disable detailed parsing of dates through the jsonserializersettings and disable it by default.
Awaiting your feedback.




0 Votes 0 ·

@siebeverschaeve Apology as I couldn't respond earlier as there was no tag previously. Surely we can help you with that. Can you create a new Microsoft Q&A post with azure-logic-apps tag and tag me in on that post for the tracking purpose. Can you confirm if the issue is observe on the output of When a resource event occurs or share more details on the repro so I can assist you further on the new Q&A post.

0 Votes 0 ·