Skip to content

Commit 2bb1e50

Browse files
authored
Merge pull request #13593 from nitsan-tzur/cyberark_epm_package_fix
Cyberark epm package fix - remove usage of lxml
2 parents 2b7c847 + 23fe3a0 commit 2bb1e50

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed
5.78 KB
Binary file not shown.

Solutions/CyberArkEPM/DataConnectors/CyberArkEPMSentinelConnector/pyepm.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,28 @@
44
Date Created: 6/10/2019 16:19
55
"""
66
import json, requests, urllib3, urllib
7-
from lxml import html
7+
from html.parser import HTMLParser
8+
9+
10+
class _SamlResponseParser(HTMLParser):
11+
def __init__(self):
12+
super().__init__()
13+
self.values = []
14+
15+
def handle_starttag(self, tag, attrs):
16+
if tag.lower() != 'input':
17+
return
18+
d = {k.lower(): v for k, v in attrs}
19+
if d.get('name') == 'SAMLResponse' and 'value' in d:
20+
self.values.append(d['value'])
21+
22+
23+
def _extract_saml_response(html_text):
24+
parser = _SamlResponseParser()
25+
parser.feed(html_text)
26+
if not parser.values:
27+
raise ValueError('SAMLResponse input not found in IdP HTML response')
28+
return parser.values[-1]
829

930
def epmAuth(dispatcher, username, password):
1031
"""
@@ -82,9 +103,7 @@ def samlAuth(dispatcher, username, password, identityTenantID, identityTenantURL
82103
}
83104
response = session.get(url, headers=headers, data = payload)
84105

85-
86-
tree = html.fromstring(response.content)
87-
samlresponse = tree.xpath('//input[@name="SAMLResponse"]/@value[last()]')[0]
106+
samlresponse = _extract_saml_response(response.text)
88107

89108
#SAML Logon
90109
url = dispatcher + "/SAML/Logon"

Solutions/CyberArkEPM/DataConnectors/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
azure-storage-file-share==12.5.0
66
azure-functions
77
requests
8-
lxml

0 commit comments

Comments
 (0)