Skip to content

Conversation

@CamClendenon
Copy link

Description

This update enhances security by adding a missing Content Security Policy (CSP) to the src/client/index.html file, within the header section. We have also included documentation to explain how the CSP tags function. It also explains how clients can add their sites to comply with the policy, ensuring they are not inadvertently blocked by the CSP.

The contributors to this work are @pogoco26 and @CamClendenon. We researched the issue, drafted the implementation, and wrote the documentation. This pull request is part of our Capstone project with CSUMB in collaboration with OED, to address security vulnerabilities, such as the above mentioned.

Type of change

  • Note merging this changes the database configuration.
  • This change requires a documentation update

Checklist

  • I have followed the OED pull request ideas
  • I have removed text in ( ) from the issue request
  • You acknowledge that every person contributing to this work has signed the OED Contributing License Agreement and each author is listed in the Description section.

Limitations

The primary limitation is uncertainty regarding how this change may affect client integrations. While no issues are expected, any problems can likely be resolved by adding the client's site to the CSP's list of allowed sources.

@CamClendenon CamClendenon marked this pull request as draft May 6, 2025 18:43
@huss
Copy link
Member

huss commented Jul 21, 2025

@CamClendenon & @pogoco26 It has been a while since the last work on this pull request. OED appreciates your work so far and OED would like to move this work forward. If you are working on this or need help then please leave a comment. If nothing is posted by 1 Aug. then OED will evaluate the work to see if it can be completed or if this PR needs to be closed.

@huss
Copy link
Member

huss commented Sep 15, 2025

@CamClendenon & @pogoco26 This is to let you know a new team is working in this area. If you don't want them to take over this work then please let me know in the near future. Thanks.

@BrianRaymond800
Copy link

I have reviewed and tested the code in this pull request. The code is functional and addresses the CSP issue, and the documentation is sufficient.

Copy link
Member

@huss huss left a comment

Choose a reason for hiding this comment

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

I've looked this over at the high level. I've made some comments to consider. In the big picture, I want better commenting and an understanding of what this is doing and if any issues exist. Also, how was/can it be tested to see it is working correctly. I'm not an expert here so I need help.

I also merged in the latest development and did minor changes.

I'm happy to help anyone with this.


import createCache from '@emotion/cache';

const nonce = (document.querySelector('script[nonce]') as HTMLScriptElement | null)?.nonce;
Copy link
Member

Choose a reason for hiding this comment

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

How does nonce relate to __webpack_nonce__ in index.tsx?

I think some commenting to describe what the code in this file is doing is needed.

* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const __webpack_nonce__ = (document.querySelector('script[nonce]') as HTMLScriptElement | null)?.nonce;
Copy link
Member

Choose a reason for hiding this comment

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

I think some commenting to describe what the new code is doing is needed.

(window as any).__webpack_nonce__ = __webpack_nonce__;
(window as any).__plotly_nonce__ = __webpack_nonce__;

console.log('Set __webpack_nonce__ to:', __webpack_nonce__);
Copy link
Member

Choose a reason for hiding this comment

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

There are a number of console.log statements. They should go before this is finalized.

Choose a reason for hiding this comment

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

@huss Could you clarify what this comment means? What is the issue with the placement of the console.log statements right now?

Copy link
Member

Choose a reason for hiding this comment

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

@huss Could you clarify what this comment means? What is the issue with the placement of the console.log statements right now?

@BrianRaymond800 console.log statements are fine for debugging but should not be present in final code. OED does not want output like this in merged code. If information needs to be given then the log system should be used. I think these are for debugging so should go when no longer needed.

Choose a reason for hiding this comment

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

@huss That makes sense. Thank you.

throw err;
}
};
// document.head.appendChild = function (node: any) {
Copy link
Member

Choose a reason for hiding this comment

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

It should be determined if this commented out code should be used or removed.

nonce="{{nonce}}">

<!--
The meta tag with "Content-Security-Policy" below is the Content Security Policy, by having default-src as self all CSP rules that are unspecified will only
Copy link
Member

Choose a reason for hiding this comment

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

Some of these lines exceed 150 characters.

a site to the exception list. Another example for adding a site (https://newException.com) to a tag with multiple sites as an exceptions would be :
img-src 'self' http://example.com https://site_example.net; becomes img-src 'self' http://example.com https://site_example.net https://newException.com;
-->
<!-- <meta http-equiv="Content-Security-Policy" content="
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering how these are working given the lines are commented out. How does this relate to the code in app.js? I think some may be examples but it needs to be clarified.

{ test: /\.css$/, use: [
{loader: 'style-loader'},
{loader: 'style-loader',
options: {
Copy link
Member

Choose a reason for hiding this comment

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

A comment on this would help.

const subdir = config.subdir || '/';
let htmlPlusData = html.toString().replace('SUBDIR', subdir);

const nonce = crypto.randomBytes(16).toString('base64url')
Copy link
Member

Choose a reason for hiding this comment

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

A comment on what this is doing would help.

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.

3 participants