Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

startswith() expects binary not string #15

Open
syserr0r opened this issue Aug 6, 2020 · 0 comments
Open

startswith() expects binary not string #15

syserr0r opened this issue Aug 6, 2020 · 0 comments

Comments

@syserr0r
Copy link

syserr0r commented Aug 6, 2020

if not self._request_xml.strip().startswith('<'):

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 added a commit to syserr0r/dj-saml-idp that referenced this issue Aug 6, 2020
self._request_xml.strip() appears to be binary, so startswith() should have a binary argument
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant