eXist-db / existdb-saml

XQuery module that implements SAML v2 single sign-on
GNU Lesser General Public License v2.1
4 stars 3 forks source link

[BUG] XDM xs:base64Binary error on eXist-db 6.x.x #23

Closed adamretter closed 11 months ago

adamretter commented 1 year ago

When trying to use the current version on eXist-db 6.x.x the following error is reported:

HTTP ERROR 500 jakarta.servlet.ServletException: jakarta.servlet.ServletException: An error occurred while processing request to /exist/apps/myapp: err:XPTY0004 xs:base64Binary(fZBBa8MwDIX/SvDdiefGXiaSQNguhe2yjt3dVKyBxM4su/TnT20ZdJeBLnrS+9BTS26ZVxhyOvp3/M5IqTgvsye4DjqRo4fgaCLwbkGCNMJueHsFXSpYY0hhDLMoti+dcMZurFWNkk/Y7GXd2FruWZCNugiWe6tF8YmRpuA7wQQ2EmXcekrOJ5aU3kjVSG0+Hgxorrp8NFIZULw7EGFM7H0OnvKCcYfxNI1sP+C5E0r07eVouDLjXYz/U7hfrOiPKa0EVUU3sOSAp+mAsQzxq63u4P2t+/u4/gc=) is not a sub-type of xs:string [at line 103, column 34, source: /db/apps/existdb-saml/content/exsaml.xqm] In function: exsaml:build-authnreq-redir-url(xs:string) [53:29:/db/apps/existdb-saml/content/exsaml.xqm]

This occurs because of the line 103 in question:

let $urlenc := xmldb:encode($zip)

At that point $zip is of type xs:base64Binary (generated by line 100: let $zip := compression:deflate($bin, true())) , but the xmldb:encode function only accepts a string. The error is caused by the fact that there is no type promotion from xs:base64Binary to xs:string in XQuery. eXist-db in older versions may have allowed such bogus type promotion.

The backward compatible fix is to instead write: xmldb:encode($zip cast as xs:string)