Skip to content

Commit

Permalink
Revert "Fix: Frame Injection (azul-private#12)" (#5197)
Browse files Browse the repository at this point in the history
This reverts commit d658544.
  • Loading branch information
dsotirho-ucsc committed May 19, 2023
1 parent fd3608b commit 235b73c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 285 deletions.
34 changes: 0 additions & 34 deletions src/azul/chalice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import (
Iterable,
)
import html
import json
from json import (
JSONEncoder,
Expand Down Expand Up @@ -37,12 +36,6 @@
from furl import (
furl,
)
from more_itertools import (
only,
)
from werkzeug.http import (
parse_accept_header,
)

from azul import (
config,
Expand Down Expand Up @@ -114,7 +107,6 @@ def __init__(self,
self._specs: Optional[MutableJSON] = None
super().__init__(app_name, debug=config.debug > 0, configure_logs=False)
# Middleware is invoked in order of registration
self.register_middleware(self._html_wrapping_middleware, 'http')
self.register_middleware(self._logging_middleware, 'http')
self.register_middleware(self._hsts_header_middleware, 'http')
self.register_middleware(self._lambda_context_middleware, 'all')
Expand Down Expand Up @@ -149,32 +141,6 @@ def patched_event_source_handler(self_, event, context):
if old_handler.__code__ != patched_event_source_handler.__code__:
chalice.app.EventSourceHandler.__call__ = patched_event_source_handler

def _html_wrapping_middleware(self, event, get_response):
"""
Embed a `text/plain` response in HTML if the request favors `text/html`.
Any HTML fragments in the original response are escaped to counteract
HTML injection attacks. This doesn't fully prevent those attacks because
a broken, ancient user agent might still request `text/plain`, `*/*` or
nothing, ignore the `text/plain` content type, sniff the HTML fragment
and render it. It does, however, handle vulnerability scanners because
those do prefer `text/html`.
"""
response = get_response(event)
ct_key = only(k for k in response.headers if k.casefold() == 'content-type')
if ct_key and response.headers[ct_key] == 'text/plain':
parsed = parse_accept_header(event.headers.get('accept'))
text_html = parsed.find('text/html')
star_star = parsed.find('*/*')
if 0 <= text_html and (star_star < 0 or text_html < star_star):
response.body = (
'<html><body>'
f'<h1>Status {response.status_code}</h1>'
f'<pre>{html.escape(json.dumps(response.body), quote=False)}</pre>'
'</body></html>'
)
response.headers[ct_key] = 'text/html'
return response

def _logging_middleware(self, event, get_response):
self._log_request()
response = get_response(event)
Expand Down
6 changes: 0 additions & 6 deletions test/app_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
Thread,
)
import time
from typing import (
Any,
ClassVar,
)

# noinspection PyPackageRequirements
from chalice.config import (
Expand Down Expand Up @@ -73,8 +69,6 @@ class LocalAppTestCase(CatalogTestCase, metaclass=ABCMeta):
ElasticsearchTestCase.
"""

app_module: ClassVar[Any]

@classmethod
@abstractmethod
def lambda_name(cls) -> str:
Expand Down
245 changes: 0 additions & 245 deletions test/test_content_type.py

This file was deleted.

0 comments on commit 235b73c

Please sign in to comment.