|
@@ -24,9 +24,8 @@ __all__ = (
|
|
|
'validate_jinja2_syntax',
|
|
'validate_jinja2_syntax',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-# Control characters (C0 range plus DEL) which are invalid in an HTTP header value. Notably, this includes the
|
|
|
|
|
-# carriage return and line feed characters used to smuggle additional headers (CR/LF injection).
|
|
|
|
|
-HTTP_HEADER_INVALID_CHARS_RE = re.compile(r'[\x00-\x1f\x7f]')
|
|
|
|
|
|
|
+# HTTP header values are encoded as Latin-1 by the HTTP client. Exclude all control characters.
|
|
|
|
|
+HTTP_HEADER_INVALID_CHARS_RE = re.compile(r'[^\x20-\x7e\xa0-\xff]')
|
|
|
|
|
|
|
|
# Matches the start of a Jinja2 expression, statement, or comment ({{, {%, {#), to detect whether a
|
|
# Matches the start of a Jinja2 expression, statement, or comment ({{, {%, {#), to detect whether a
|
|
|
# template-capable field (e.g. Webhook.payload_url) is being used as a literal value or a template.
|
|
# template-capable field (e.g. Webhook.payload_url) is being used as a literal value or a template.
|
|
@@ -47,9 +46,8 @@ def env_filter(name):
|
|
|
|
|
|
|
|
def sanitize_http_header(value):
|
|
def sanitize_http_header(value):
|
|
|
"""
|
|
"""
|
|
|
- Jinja2 filter which sanitizes a value for safe inclusion in a raw HTTP header by stripping newlines and other
|
|
|
|
|
- control characters. This guards against HTTP header (CR/LF) injection when interpolating untrusted data (e.g.
|
|
|
|
|
- user-controlled object attributes) into a webhook's additional headers.
|
|
|
|
|
|
|
+ Jinja2 filter which removes control characters and characters outside the Latin-1 character set from HTTP
|
|
|
|
|
+ header values. This prevents header injection when interpolating untrusted data into webhook headers.
|
|
|
"""
|
|
"""
|
|
|
return HTTP_HEADER_INVALID_CHARS_RE.sub('', str(value))
|
|
return HTTP_HEADER_INVALID_CHARS_RE.sub('', str(value))
|
|
|
|
|
|