dj-saml-idp icon indicating copy to clipboard operation
dj-saml-idp copied to clipboard

startswith() expects binary not string

Open syserr0r opened this issue 5 years ago • 0 comments

https://github.com/mobify/dj-saml-idp/blob/8ee1d65a1434c58726b0f34aeb28b0964f3e6289/saml2idp/base.py#L215

Should instead be if not self._request_xml.strip().startswith(b'<'): At least on Python 3 -- not checked if this breaks Python 2.

I'm currently monkey-patching with the following code:

from bs4 import BeautifulSoup
from saml2idp.base import CaseInsensitiveDict
import saml2idp.base


def _parse_request(self):
    """
    Parses various parameters from _request_xml into _request_params
    """
    # Minimal test to verify that it's not binarily encoded still:
    if not self._request_xml.strip().startswith(b'<'):
        raise Exception(
            'RequestXML is not valid XML; ' 'it may need to be decoded or decompressed.'
        )
    soup = BeautifulSoup(self._request_xml, 'xml')
    request = soup.findAll()[0]

    # BeautifulSoup 4 uses case-dependent matching where v3 forced
    # all names to lowercase, so we emulate that behaviour.
    attrs = CaseInsensitiveDict(request.attrs)
    self._request_params = dict(
        ACS_URL=attrs['assertionconsumerserviceurl'],
        REQUEST_ID=attrs['id'],
        DESTINATION=attrs.get('destination', ''),
        PROVIDER_NAME=attrs.get('providername', ''),
    )

saml2idp.base.Processor._parse_request = _parse_request

syserr0r avatar Aug 06 '20 12:08 syserr0r