Fix error in python3-saml: A valid SubjectConfirmation was not found
Problem
If the assertion returned by IdP is encrypted, I am seeing this error:
A valid SubjectConfirmation was not found on this Response
This problem only happens when the assertion returned is encrypted. If it is plain, then no such problem.
My environment:
- Ubunut: 22.04 LTS
- Python 3.10
- Python3-saml 1.14.0
The error was raised in these 2 lines (source code >>):
1 | sc_data = scn.find('saml:SubjectConfirmationData', namespaces=OneLogin_Saml2_Constants.NSMAP) |
I printed the scn, like print(tostring(scn))
and the xml clearly shows that it has a child node <SubjectConfirmationData>
, but the find
keeps returning None
. What is more strange, if I recreate the scn node:
1 | new_scn = fromstring(tostring(scn)) |
This actually works.
After keep debugging and searching for a whole day, it turns out it is a problem in python pre-built lxml package.
Solution
In my case, I reinstall lxml with no binary option:
1 | $ pip uninstall lxml |
If using requirements.txt:
1 | lxml==4.7.0 |
Currently the python3-saml repo is currently not under active development, I hope they fix this in the future version.