Skip to content

Commit 295d9a8

Browse files
Merge pull request #610 from peppelinux/deprecation_warnings
Use html.escape when available
2 parents 7ba4338 + e86a489 commit 295d9a8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/saml2/pack.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"""
99

1010
import base64
11-
import cgi
11+
try:
12+
import html
13+
except:
14+
import cgi as html
15+
1216
import logging
1317

1418
import saml2
@@ -64,6 +68,10 @@
6468
</html>"""
6569

6670

71+
def _html_escape(payload):
72+
return html.escape(payload, quote=True)
73+
74+
6775
def http_form_post_message(message, location, relay_state="",
6876
typ="SAMLRequest", **kwargs):
6977
"""The HTTP POST binding defines a mechanism by which SAML protocol
@@ -87,15 +95,15 @@ def http_form_post_message(message, location, relay_state="",
8795
_msg = _msg.decode('ascii')
8896

8997
saml_response_input = HTML_INPUT_ELEMENT_SPEC.format(
90-
name=cgi.escape(typ),
91-
val=cgi.escape(_msg),
98+
name=_html_escape(typ),
99+
val=_html_escape(_msg),
92100
type='hidden')
93101

94102
relay_state_input = ""
95103
if relay_state:
96104
relay_state_input = HTML_INPUT_ELEMENT_SPEC.format(
97105
name='RelayState',
98-
val=cgi.escape(relay_state),
106+
val=_html_escape(relay_state),
99107
type='hidden')
100108

101109
response = HTML_FORM_SPEC.format(

0 commit comments

Comments
 (0)