- Python
- Language
- Hello World
- Variables
- Functions
- Conditional
- Operators
- While
- Turtle
- Script Mode
- Debugging
- Strings
- Slice
- Raw
- Validation
- Config
- Security ♣
- Collections
- Lists
- Dictionaries
- Efficiency
- Tree
- Iterator
- Tuples
- References
- Functions
- Recursion
- Factorial
- Modulus
- Reassignment
- Approximate
Escape
Prevent xss attacks with html escape.
""" XSS
Prevent cross site scriting attacks
Escape html tags with html library
"""
import html
a = """& < " ' >"""
x = html.escape(a)
b = "<script>alert('hack');</script>"
y = html.escape(b)
print(x) # & < " ' >
print(y) # <script>alert('hack');</script>
XML
The sax library escape should execute faster.
""" XSS
Prevent cross site scriting attacks
The sax library escape should execute faster
"""
from xml.sax.saxutils import escape
from xml.sax.saxutils import quoteattr
a = '< & >'
x = escape(a)
b = "a ' b"
y = quoteattr(b)
assert x == '< & >'
assert y == '"a \' b"'
print('pass')