mbg / wai-saml2

WAI middleware implementing SAML2
MIT License
5 stars 6 forks source link

Truncate IssueInstant #40

Closed fumieval closed 1 year ago

fumieval commented 1 year ago

Checklist

I drew a conclusion too early when I saw iso8601Show <$> getCurrentTime showing 6 decimal places... I realised that it may still show more decimal places if depending on the environment, causing parse errors on AzureAD.

iso8601Show $ UTCTime (toEnum 0) (picosecondsToDiffTime 1)
"1858-11-17T00:00:00.000000000001Z"

This change circumvents the problem by truncating the timestamp to 26 characters and appending 'Z'. I wish time package had a way to specify the number of decimal places...

ghci> length "2023-01-21T10:29:37.649776Z"
27
mbg commented 1 year ago

I wish time package had a way to specify the number of decimal places...

This is possible using a <width> modifier (see the Data.Time.Format documentation). For example:

ghci> let timeFormat = "%Y-%m-%dT%H:%M:%S%6QZ"
ghci> formatTime defaultTimeLocale timeFormat $ UTCTime (toEnum 0) (picosecondsToDiffTime 1)
"1858-11-17T00:00:00.000000Z"

The key point is the %6Q part which specifies that we want the decimal point and fraction of second, truncated to at most 6 digits. The documentation is not great here and only talks about "padding", but when the specified width is smaller than the actual length of the value, then this modifier will also truncate the string.

fumieval commented 1 year ago

That's good to know. I updated the code to use %Y-%m-%dT%H:%M:%S%6QZ