- BASICS
- Statements
- Operators
- Functions
- Incremental
- Errors
- FUNCTIONS
- Function Definition
- Recursion
- Objects
- STRINGS
- Immutable
- Raw Strings
- Regex
- Validation
- Config
-
Security
- Encrypt
- CLASS
- Definition
- Attributes
- Functional
- Methods
- COLLECTIONS
- Lists
- List Comprehension
- Dictionaries
- Dictionary Efficiency
- Tuples
- References
- Iterable
- STORAGE
- Files
- Databases
- Pipes
- With Open
- Shelve
- Zip
- Csv
- Json
PYTHON PAGES - LEVEL 1
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')
Questions and answers:
Clink on Option to Answer
1. To prevent XSS attacks you must:
- a) escape user input
- b) validate user output