From 4475869203dd953517d35345c0590ae287581de8 Mon Sep 17 00:00:00 2001 From: tabraiz Date: Tue, 27 Aug 2024 21:04:13 +0530 Subject: [PATCH 1/7] fixes unsafe fixes --- contributing-frontend.md | 2 +- desktop/core/src/desktop/auth/views.py | 2 + desktop/core/src/desktop/decorators.py | 13 ++++++ desktop/core/src/desktop/middleware.py | 15 +++++++ desktop/core/src/desktop/settings.py | 1 + .../src/desktop/templates/common_footer.mako | 2 +- .../src/desktop/templates/common_header.mako | 32 +++++++------- .../common_header_footer_components.mako | 6 +-- .../common_notebook_ko_components.mako | 6 +-- .../templates/config_ko_components.mako | 18 ++++---- desktop/core/src/desktop/templates/hue.mako | 42 ++++++++++--------- .../templates/hue_ace_autocompleter.mako | 4 +- desktop/core/src/desktop/templates/login.mako | 4 +- .../src/desktop/templates/login_modal.mako | 2 +- desktop/core/src/desktop/views.py | 7 +++- 15 files changed, 97 insertions(+), 59 deletions(-) diff --git a/contributing-frontend.md b/contributing-frontend.md index 5a6a203ea86..76fd8a2fde7 100644 --- a/contributing-frontend.md +++ b/contributing-frontend.md @@ -19,7 +19,7 @@ A react root element (or the first container element within it) must include the If your react component isn't dependent on any Knockout observables or Vue components you can integrate it by adding a small script and a component reference directly in the HTML code. The following example integrates MyComponent as a react root in an HTML/mako file. ```HTML - + % endif % if not conf.DEV.get(): - + % endif % for bundle in get_hue_bundles('login' if section == 'login' else 'hue', 'LOGIN' if section == 'login' else 'DEFAULT'): - ${ render_bundle(bundle, config='LOGIN' if section == 'login' else 'DEFAULT') | n,unicode } + ## Instead of trying to assign to a variable, directly operate within expressions. + ${render_bundle(bundle, config='LOGIN' if section == 'login' else 'DEFAULT').replace(' - - - - - - + + + + + + + + % if user.is_authenticated: ${ hueAceAutocompleter.hueAceAutocompleter() } @@ -168,9 +170,9 @@ if USE_NEW_EDITOR.get(): ${ commonHeaderFooterComponents.header_pollers(user, is_s3_enabled, apps) } % if user.is_authenticated: - + - % endif @@ -556,8 +558,8 @@ ${ hueIcons.symbols() } - - + - - - - - - - - - - - - - + + % if not conf.DEV.get(): - + % endif @@ -110,8 +110,8 @@ - - + - - - - - - - - + + + + + - + + + + - + + @@ -334,7 +336,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode } -${ commonHeaderFooterComponents.footer(messages) } +${ commonHeaderFooterComponents.footer(messages, csp_nonce) } ## This includes common knockout templates that are shared with the Job Browser page and the mini job browser panel ## available in the upper right corner throughout Hue diff --git a/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako b/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako index e958e2586b8..5627f5a358d 100644 --- a/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako +++ b/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako @@ -356,7 +356,7 @@ else: - - -${ commonfooter(None, messages) | n,unicode } +${ commonfooter(None, messages, False, request.csp_nonce) | n,unicode } diff --git a/desktop/core/src/desktop/templates/login_modal.mako b/desktop/core/src/desktop/templates/login_modal.mako index 73778d86896..4e4f9a5f389 100644 --- a/desktop/core/src/desktop/templates/login_modal.mako +++ b/desktop/core/src/desktop/templates/login_modal.mako @@ -49,7 +49,7 @@ - + % endif % if not conf.DEV.get(): - + % endif % for bundle in get_hue_bundles('login' if section == 'login' else 'hue', 'LOGIN' if section == 'login' else 'DEFAULT'): - ## Instead of trying to assign to a variable, directly operate within expressions. - ${render_bundle(bundle, config='LOGIN' if section == 'login' else 'DEFAULT').replace(' - - - - - - + + + + + + + % if user.is_authenticated: ${ hueAceAutocompleter.hueAceAutocompleter() } @@ -170,9 +168,9 @@ if USE_NEW_EDITOR.get(): ${ commonHeaderFooterComponents.header_pollers(user, is_s3_enabled, apps) } % if user.is_authenticated: - + - % endif @@ -558,8 +556,8 @@ ${ hueIcons.symbols() } - - + - - - - - - - - - - - - - + + % if not conf.DEV.get(): - + % endif @@ -110,8 +112,8 @@ - - + + + + + - - - - - + + + + - - - - + - - - @@ -336,7 +337,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode } -${ commonHeaderFooterComponents.footer(messages, csp_nonce) } +${ commonHeaderFooterComponents.footer(messages, nonce) } ## This includes common knockout templates that are shared with the Job Browser page and the mini job browser panel ## available in the upper right corner throughout Hue diff --git a/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako b/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako index 5627f5a358d..aa0f94d4089 100644 --- a/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako +++ b/desktop/core/src/desktop/templates/hue_ace_autocompleter.mako @@ -23,6 +23,7 @@ if sys.version_info[0] > 2: from django.utils.translation import gettext as _ else: from django.utils.translation import ugettext as _ +from desktop.lib.django_util import nonce_attribute %> <%def name="hueAceAutocompleter()"> @@ -356,7 +357,7 @@ else: - - -${ commonfooter(None, messages, False, request.csp_nonce) | n,unicode } +${ commonfooter(request, messages, nonce ) | n,unicode } diff --git a/desktop/core/src/desktop/templates/login_modal.mako b/desktop/core/src/desktop/templates/login_modal.mako index 4e4f9a5f389..1187e296e9b 100644 --- a/desktop/core/src/desktop/templates/login_modal.mako +++ b/desktop/core/src/desktop/templates/login_modal.mako @@ -22,7 +22,7 @@ from django.utils.translation import gettext as _ else: from django.utils.translation import ugettext as _ - + from desktop.lib.django_util import nonce_attribute from useradmin.hue_password_policy import is_password_policy_enabled, get_password_hint %> @@ -49,7 +49,7 @@ -