Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[security] Unsafe Inline Script #3876

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

[security] Unsafe Inline Script #3876

wants to merge 9 commits into from

Conversation

tabraiz12
Copy link
Collaborator

Have Closed the existing PR, splitting the PR to smaller PR for easier Review:

Upcoming PRs:

  1. Unsafe Inline Script
  2. Unsafe Inline Style
  3. Backend Configuration for per page unsafe-eval, this is so that we will initially only allow editor.
  4. Unsafe Eval - Editor Page, Login
  5. Unsafe Eval - Admin Page
  6. Unsafe-Eval - NoteBook, and others

What changes were proposed in this pull request?

  • Added a middleware to add request.nonce and include it in the request script
  • Added unsafe-eval in CSP for temporarily handling the ko bindings, this fix will be part of another PR.

How was this patch tested?

  1. Manual Test
  2. Testes Login
  3. Tested Editor and running few commands
  4. Navigated to job browser and admin pages didn't find any js issues.
  5. Removed the nonce attribute and verified that its throwing error without those.

Please review Hue Contributing Guide before opening a pull request.

Copy link
Collaborator

@Harshg999 Harshg999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall! I've added few review comments..

@@ -137,6 +137,9 @@ http_500_debug_mode=false
# X-Content-Type-Options: nosniff This is a HTTP response header feature that helps prevent attacks based on MIME-type confusion.
## secure_content_security_policy="script-src 'self' 'unsafe-inline' 'unsafe-eval' *.googletagmanager.com *.doubleclick.net data:;img-src 'self' *.doubleclick.net http://*.tile.osm.org *.tile.osm.org *.gstatic.com data:;style-src 'self' 'unsafe-inline' fonts.googleapis.com;connect-src 'self' *.google-analytics.com;frame-src *;child-src 'self' data: *.vimeo.com;object-src 'none'"

# Enable nonce attribute to remove unsafe-inline and auto remove unsafe-inline from csp
## csp_nonce=True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: true

@@ -142,6 +142,10 @@
# X-Content-Type-Options: nosniff This is a HTTP response header feature that helps prevent attacks based on MIME-type confusion.
## secure_content_security_policy="script-src 'self' 'unsafe-inline' 'unsafe-eval' *.googletagmanager.com *.doubleclick.net data:;img-src 'self' *.doubleclick.net http://*.tile.osm.org *.tile.osm.org *.gstatic.com data:;style-src 'self' 'unsafe-inline' fonts.googleapis.com;connect-src 'self' *.google-analytics.com;frame-src *;child-src 'self' data: *.vimeo.com;object-src 'none'"

# Enable nonce attribute to remove unsafe-inline and auto remove unsafe-inline from csp
## csp_nonce=True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: true

Comment on lines +524 to +525
# Assuming 'csp_nonce' is set in the request and CSP_NONCE controls its usage
if desktop.conf.CSP_NONCE.get():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of assuming, why not check for it by using hasattr()?

Comment on lines +527 to +529
if csp_nonce:
return f' nonce={csp_nonce}'
return ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Try something like this once?

return f' nonce={csp_nonce}' if csp_nonce else ''

Comment on lines +875 to +876
nonce = secrets.token_urlsafe()
request.csp_nonce = nonce
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

'text script': function (text) {
return text;
}
'text script': text => text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, was this change needed or just an improvement?

@@ -295,8 +296,9 @@ ${ hueIcons.symbols() }
</div>
${ commonshare() | n,unicode }

% for bundle in get_hue_bundles('hue'):
${ render_bundle(bundle) | n,unicode }
% for bundle in get_hue_bundles('login' if section == 'login' else 'hue', 'LOGIN' if section == 'login' else 'DEFAULT'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the login related checks for hue.mako?

<script type="application/json" id="editorOptionsJson">
${ options_json | n,unicode,antixss }
</script>
<script ${nonce_attribute(request)} src="${ static('desktop/js/editor-component.js') }"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing js file in the commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants